解决“chrome正受到自动测试软件的控制”信息栏显示问题(转)

在使用Selenium WebDriver启动谷歌浏览器Chrome时,在新启动的浏览器地址栏下方经常会显示一行提示信息:“chrome正受到自动测试软件的控制”,英文的就是“'Chrome is being controlled by automated test software'。

我们可以通过引入ChromeOptions类来解决这个问题,ChromeOptions类中定义的一些方法,可以指定Chrome浏览器以特定的方式去启动,通过传参数“disable-infobars”,可以让Chrome浏览器在启动时不显示信息栏。

下面是基于Java语言的解决示例:
 

package learnwebdriver;
 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
 
public class UseBrowserChrome {
 
    public static void main(String[] args) {
        
        System.setProperty("webdriver.chrome.driver", "D:\\BrowserDriver\\chromedriver.exe");
        
        //取消 chrome正受到自动测试软件的控制的信息栏
        ChromeOptions options = new ChromeOptions();
        options.addArguments("disable-infobars");
        
        //带参数启动Chrome浏览器
        WebDriver driver = new ChromeDriver(options);        
        
        driver.manage().window().maximize();        
        
        driver.get("http://www.baidu.com/");
        
        
        //driver.quit();
        
 
    }
 
}


---------------------
作者:YOYO测试
来源:CSDN
原文:https://blog.csdn.net/yoyocat915/article/details/79758000
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/lixiaomei0623/article/details/89283711