在使用Selenium WebDriver启动谷歌浏览器Chrome时,在新启动的浏览器地址栏下方经常会显示一行提示信息:“chrome正受到自动测试软件的控制”,英文的就是“'Chrome is being controlled by automated test software'。
之前我们去掉这个信息栏的做法是传“disable-infobars”参数给chrome driver,但是现在在新版本的chrome浏览器及对应driver中(V76及以上版本),这个参数被废弃掉了,已经无效了。
注:本文的解决方法针对的是V76及以上的谷歌版本及对应driver。
旧版本的解法方法请见:/yoyocat915/article/details/79758000
在新版本的chrome浏览器中我们可以通过下面的方法来禁掉这个信息栏的显示:
ChromeOptions option = new ChromeOptions();option.setExperimentalOption("useAutomationExtension", false); option.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));WebDriver driver = new ChromeDriver(option);
Java完整示例如下:
package com.yoyotesting.selenium3maven;import java.util.Collections;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.chrome.ChromeOptions;public class DisableChromeInfobar {public static void main(String[] args) {System.setProperty("webdriver.chrome.driver", "D:\\browserdriver\\chrome77\\chromedriver.exe");ChromeOptions option = new ChromeOptions();//通过ChromeOptions的setExperimentalOption方法,传下面两个参数来禁止掉谷歌受自动化控制的信息栏option.setExperimentalOption("useAutomationExtension", false); option.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));WebDriver driver = new ChromeDriver(option);driver.manage().window().maximize();driver.get("");}}
********************************************************************************************************
近期我会在博客中系统的更新一些关于Selenium的文章,也请大家多多关注下我的视频课程:
入门:基于Java的Selenium3自动化测试完整教程
高级:Selenium Java高级架构课程
*********************************************************************************************************
精彩文章,请大家关注我的测试公众号:火烈鸟测试