用Selenium自动化测试时,让ChromeDriver中不显示“正受到自动测试软件控制”

背景:

在用Selenium做自动化测试的时候,默认ChromeDriver是会提示“Chrom正受到自动测试软件控制”的。如下图这样。但我们有些场景下,不希望这个提示出现。本文探索了几种语言去掉这个提示条的方法,希望对小伙伴有帮助。

 

 1. Java

ChromeOptions options = new ChromeOptions(); 
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"}); 
WebDriver driver = new ChromeDriver(options); 

2. C#

ChromeOptions options = new ChromeOptions();
options.AddExcludedArgument("enable-automation");
options.AddAdditionalCapability("useAutomationExtension", false);
IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("http://www.baidu.com");

3. Python

chrome_options = webdriver.ChromeOptions(); 
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']);
driver = webdriver.Chrome(options=chrome_options);

4. JavaScript

var chromeCapabilities=webdriver.Capabilities.chrome()
var chromeOptions = {
        'excludeSwitches': ['enable-automation']
};
chromeCapabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder()
    .withCapabilities(chromeCapabilities)
    .build();

 

  

posted @ 2019-12-12 23:57  Snow~Forever  阅读(2586)  评论(0编辑  收藏  举报