今天突然有同时问 selenium 怎么去掉浏览器默认的 “chrome正受到自动测试软件的控制”信息栏显示问,说是百度好多文章都说是通过设置disable-infobars属性可以解决,尝试后都不行,最后去谷歌找了下发现是新版本中该属性已经被废弃导致的,具体如下:
Recent versions of Chrome display notification bar at the top of the browser saying "Chrome is being controlled by automated test software", as follows:
Previously, passing the "disable-infobars” ChromeOption to the WebDriver prevented Chrome from displaying this notification. Recently, the "disable-infobars" option has been deprecated and no longer removes the notification. The current workaround for this is to pass in an option called "excludeSwitches" and then exclude the "enable_automation" switch.
java 或python的解决方法:
java:
```
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
WebDriver driver = new ChromeDriver(options);
```
python3
```
chrome_options = webdriver.ChromeOptions();
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']);
driver = webdriver.Chrome(options=chrome_options);
```
参考原文:
https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification