在使用Selenium WebDriver启动谷歌浏览器Chrome时,在新启动的浏览器地址栏下方经常会显示一行提示信息:“chrome正受到自动测试软件的控制”,英文的就是“'Chrome is being controlled by automated test software'。
两个方法:
我使用第一个方法可行,使用第二个无法去掉,大家可以尝试尝试使用一个即可。
方法一:
//估计是版本的问题,我使用其他的并不能去掉提示
//使用该代码可正常去掉提示
@Test
public void test2(){
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
//取消 chrome正受到自动测试软件的控制的信息栏
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("http://www.baidu.com/");
//driver.quit();
}
方法二:
// 可以添加该代码试试,如果不行使用上面的
// 我使用这个是无法去掉提示的
@Test
public void test2(){
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
//取消 chrome正受到自动测试软件的控制的信息栏
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
//带参数启动Chrome浏览器
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("http://www.baidu.com/");
//driver.quit();
}
后台静默启动浏览器
@Test
public void test2(){
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
//取消 chrome正受到自动测试软件的控制的信息栏
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
// 开启静默模式
options.addArguments("--headless");
//带参数启动Chrome浏览器
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("http://www.baidu.com/");
//driver.quit();
}