背景:
在用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();
标签:enable,Selenium,自动测试,driver,ChromeDriver,ChromeOptions,new,options From: https://www.cnblogs.com/guanshan/p/guan20230420_001.html