可以一起添加Chrome选项和功能吗?
System.setProperty("webdriver.chrome.driver", Base_Page.getConstant(Constant.CHROME_DRIVER_DIRECTORY));
ChromeOptions options = new ChromeOptions();
string[] switches = {"user-data-dir=C:\\Users\\AppData\\Local\\Google\\Chrome\\User Data"};
options.addArguments("user-data-dir=C:\\Users\\AppData\\Local\\Google\\Chrome\\User Data");
options.addArguments("test-type");
options.addArguments("--start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("no-sandbox");
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
options.(CapabilityType.LOGGING_PREFS, logPrefs);
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(caps);
DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
caps.setCapability("chrome.switches", switches);
//webdriver = new ChromeDriver(caps);
webdriver = new ChromeDriver(options);
搜索了同样的问题。答案是:只需将所有功能添加到“选项”对象中,然后使用选项启动浏览器:
ChromeOptions options = new ChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
webdriver = new ChromeDriver(options);
更新到最新版本的Chrome驱动程序修复了我的问题:ChromeDriver 2.28
如果你在下面的链接中观察ChromeDriver构造函数
http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeDriver.html
它将接受任何功能或选项。我希望它能让你清楚。