在selenium web driver中不添加IE驱动或Chrome驱动,如何启动已安装的浏览器?



我的电脑已经安装了IE和chrome浏览器。我想运行我的硒脚本从原来的浏览器与所有附加组件和默认设置。

我能够找到浏览器的*.exe与一些功能。但是无法在浏览器中写入和打开链接(driver.get())。请参考以下代码。

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, DriverTestNG.url);
DesiredCapabilities.internetExplorer().setCapability("ignoreProtectedModeSettings", true);
System.setProperty("webdriver.ie.driver", "src/main/resources/Framework/Drivers/Windows/IEDriverServer_Win32_2.40.0/IEDriverServer.exe");
cap.setCapability("IE.binary", "C:\Program Files\Internet Explorer\iexplore.exe");
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setJavascriptEnabled(true);
cap.setCapability("requireWindowFocus", true);
cap.setCapability("enablePersistentHover", false);
cap.setCapability("elementScrollBehavior", 1);
cap.setCapability("cssSelectorsEnabled", true);
cap.setCapability("nativeEvents", true);
driver = new InternetExplorerDriver(cap);

也许我错过了什么。我不确定selenium web driver是否支持此功能。

请给我指路。

关于你的标题,你不能运行Internet Explorer或Chrome没有使用webDriver,因为你需要webDriver作为API访问IE或Chrome的功能。

但是你仍然可以使用扩展和默认设置。您没有看到任何扩展运行chromeDriver的原因是,它总是为每个测试会话创建一个新的临时配置文件。如果你想用扩展和设置运行你自己的自定义配置文件,你必须通过定义user-data-dir来告诉chromeDriver它应该使用哪个用户配置文件。

你可以在这里找到功能:https://sites.google.com/a/chromium.org/chromedriver/capabilities

的例子:

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data");

还可以使用以下命令指定扩展名:https://sites.google.com/a/chromium.org/chromedriver/extensions

我不使用IEdriver,所以我不能告诉你它是如何与IE工作的,但据我所知,IE没有配置文件和扩展管理在注册表的某个地方。所以我假设在运行测试之前安装的扩展也可以通过IEWebDriver获得。

最新更新