无法在带有 Selenium 的 IE 11 上的关闭窗口上找到元素

我正在尝试在使用 Selenium WebDriver 的 Internet Explorer 11 上运行测试.代码是:

System.setProperty("webdriver.ie.driver", "Path/to//IEDriverServer.exe");WebDriver driver = new InternetExplorerDriver();driver.get("www.google.com");driver.findElement(By.name("q"));

我得到这个错误:

<块引用>

已启动 InternetExplorerDriver 服务器(64 位)2.46.0.0 监听端口 43760 线程主"org.openqa.selenium.NoSuchWindowException 中的异常:无法找到元素关闭窗口(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:15毫秒构建信息:版本:2.46.0",修订:'61506a4624b13675f24581e453592342b7485d71',时间:'2015-06-0410:22:50' 系统信息:主机:'user1-PC',ip:'10.0.23.71',os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.8.0_45' 驱动程序信息:org.openqa.selenium.ie.InternetExplorerDriver功能 [{browserAttachTimeout=0, enablePersistentHover=true,ie.forceCreateProcessApi=false,pageLoadStrategy=normal,ie.usePerProcessProxy=false,ignoreZoomSetting=false,handleAlerts=true,版本=11,平台=WINDOWS,nativeEvents=true,ie.ensureCleanSession=false,elementScrollBehavior=0,ie.browserCommandLineSwitches=, requireWindowFocus=false,browserName=互联网浏览器,initialBrowserUrl=

I'm trying to run tests on Internet Explorer 11 working with Selenium WebDriver. The code is:

System.setProperty("webdriver.ie.driver", "Path/to//IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver();
driver.get("www.google.com");
driver.findElement(By.name("q"));

And I get this error:

Started InternetExplorerDriver server (64-bit) 2.46.0.0 Listening on port 43760 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: 15 milliseconds Build info: version: '2.46.0', revision: '61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50' System info: host: 'user1-PC', ip: '10.0.23.71', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45' Driver info: org.openqa.selenium.ie.InternetExplorerDriver Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:43760/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}] Session ID: 8a5b7ab5-862a-462d-ab4b-929d4ed5b71a *** Element info: {Using=name, value=q} 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:204) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:358) at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:431) at org.openqa.selenium.By$ByName.findElement(By.java:300) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:350) at MySel20Proj.MySel20Proj.App.main(App.java:42)

I tried to follow the configure tutorial on https://code.google.com/p/selenium/wiki/InternetExplorerDriver but is still not working. And this code works on Firefox and Chrome.

解决方案

Try going to Internet Options --> Security --> "Enable Protected Mode" on ALL zones should either be checked or ALL unchecked.

相关文章