亲宝软件园·资讯

展开

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

Snow~Forever 人气:0

背景:

在用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();

 

  

加载全部内容

相关教程
猜你喜欢
用户评论