在使用Selenium WebDriver启动谷歌浏览器Chrome时,在新启动的浏览器地址栏下方经常会显示一行提示信息:“chrome正受到自动测试软件的控制”,英文的就是“'Chrome is being controlled by automated test software'。
之前我们去掉这个信息栏的做法是传“disable-infobars”参数给chrome driver,但是现在在新版本的chrome浏览器及对应driver中(V76及以上版本),这个参数被废弃掉了,已经无效了。
注:本文的解决方法针对的是V76及以上的谷歌版本及对应driver。
旧版本的解法方法请见:https://blog.csdn.net/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("https://www.baidu.com"); }}
**********************************************************************************************
文章来源:CSDN 作者:YOYO测试
来源地址:https://blog.csdn.net/yoyocat915/article/details/102813901