Wan*_*rer 22 java selenium internet-explorer browser-automation
我试图在IE11中使用selenium自动化网页.我已将保护模式设置设置为相同级别,缩放级别为100%.在运行测试时,它打开了网站但是刚刚发布了例外.以下是使用的代码.
File file = new File("C:\\Users\\Desktop\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath() );
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
WebDriver driver = new InternetExplorerDriver(capabilities);
driver.get("http://www.google.com");
Run Code Online (Sandbox Code Playgroud)
和异常堆栈跟踪
Started InternetExplorerDriver server (32-bit)
2.39.0.0
Listening on port 38122
Jul 11, 2014 1:50:02 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed
Jul 11, 2014 1:50:02 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 18 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'Neeraj', ip: '10.136.180.161', os.name: 'Windows 7', s.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_60' Session ID: ab6edd65-8a66-41fa-be46-56fba7dbdfc9
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=11, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=true, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=http://localhost:38122/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:348)
at org.openqa.selenium.By$ById.findElement(By.java:220)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
at Test1.main(Test1.java:27)
Run Code Online (Sandbox Code Playgroud)
有关如何解决此问题的任何建议.
Sit*_*ana 23
首先,不要使用
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
Run Code Online (Sandbox Code Playgroud)
因为您已经设置了保护模式设置.对于您看到的问题,应该是因为缺少注册表设置作为在IE11中运行测试的先决条件而添加的:
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
Sol*_*aja 11
我使用IE 11 - 64位Windows机器.这一点对我有用.
仅对于IE 11,您需要在目标计算机上设置一个注册表项,以便驱动程序可以维护与其创建的Internet Explorer实例的连接.
对于32位Windows安装,您必须在注册表编辑器中检查的密钥是HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.
对于64位Windows安装,密钥为HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.
请注意,FEATURE_BFCACHE子项可能存在也可能不存在,如果不存在,则应创建该子项.
要点:在此键内,创建一个DWORD名为iexplore.exe0的值.
@David Kemp建议的解决方案不适用于11位窗口10 - 64位.我已经HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet explorer\Main\FeatureControl\FEATURE_BFCACHE 按照IE 11中提到的步骤添加了注册表项 ,仅在https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration之后,但在打开https证书页面后(url https:// my-)页面:9443)它无法执行 driver.navigate().to("javascript:document.getElementById('overridelink').click()");抛出NoSuchWindowException
然而,同样适用于11位Windows 7-64位且能够执行脚本.
让11为win 10工作的工作是将initialBrowserUrl功能设置为 https:// my-page:9443, 如下所示
capabilities.setCapability("initialBrowserUrl", "https://my-page:9443");
Run Code Online (Sandbox Code Playgroud)
但我仍然感到困惑为什么ie11/windows 10它有所不同?