How to disable notification in chrome browser using selenium web driver with java

To perform automation with chrome browser’s tools selenium provide the ChromeOptions class in selenium lib. A class which contains the method to perform the operation like Proxy setting in the browser, enable popup, disable notification etc.

How to disable notification in selenium web driver with java.

The key point of the task.

Create a object of ChromeOptions class

ChromeOptions options = new ChromeOptions();

Call the method addArguments()

options.addArguments("disable-infobars");

Pass the object of ChromeOptions class in ChromeDriver.

WebDriver driver = new ChromeDriver(options);

Complete example to disable notification in selenium web driver with the example.

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.chrome.ChromeOptions;



public class HandlePopUP {



public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","D:\\Automation\\chromedriver_win32\\chromedriver.exe");

ChromeOptions options = new ChromeOptions();

options.addArguments("disable-infobars");

WebDriver driver = new ChromeDriver(options);

driver.get("http://www.google.com");

}

}

Open chrome browser as maximized in selenium web driver using java

The process should be same you just need to pass “start-maximized” String to “addArguments(“disable-infobars”)” method.

How to open chrome browser as maximized in selenium web driver

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.chrome.ChromeOptions;



public class HandlePopUP {



public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver", "D:\\Automation\\chromedriver_win32\\chromedriver.exe");

ChromeOptions options = new ChromeOptions();

options.addArguments("disable-infobars");

options.addArguments("start-maximized");

WebDriver driver = new ChromeDriver(options);

driver.get("http://www.google.com");

}



}

 

 

 

 

Add a Comment

Your email address will not be published. Required fields are marked *

12 − 9 =