首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >IE 11中的Selenium - NoSuchWindowException

IE 11中的Selenium - NoSuchWindowException
EN

Stack Overflow用户
提问于 2014-07-15 06:03:55
回答 7查看 62.1K关注 0票数 22

我正在尝试使用IE11中的selenium自动化一个网页。我已将保护模式设置为相同级别,缩放级别为100%。在运行测试时,它会打开网站,但随后会给出异常。下面是使用的代码。

代码语言:javascript
复制
   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");

和异常堆栈跟踪

代码语言:javascript
复制
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)

关于如何解决此问题的任何建议。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2014-07-15 08:46:23

首先,不要使用

代码语言:javascript
复制
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);

因为您已经设置了保护模式设置。对于您看到的问题,这应该是因为缺少注册表设置,这些设置是作为在IE11中运行测试的先决条件添加的:

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

票数 24
EN

Stack Overflow用户

发布于 2016-08-11 16:54:56

如果从当前页面导航到下一页的某个操作/事件,并且selenium驱动程序无法识别窗口,则以下解决方案也适用:-

对于64位Windows安装,关键是:

代码语言:javascript
复制
 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet explorer\Main\FeatureControl\FEATURE_BFCACHE

在其中创建一个名为iexplore.exe的DWORD值,其值为0。

票数 3
EN

Stack Overflow用户

发布于 2016-07-11 18:47:08

我发现,如果启动的浏览器保持在焦点上,你就会得到异常。一旦启动webdriver,就可以打开任何其他窗口,例如,只要脚本启动IE Driver,就可以打开eclipse。脚本执行开始,然后您可以打开您的IE驱动程序。要通过脚本处理它,需要添加以下代码:

代码语言:javascript
复制
    public WebDriver driver, driver1;
    System.setProperty("webdriver.ie.driver", System.getProperty(
                    "webdriver.ie.driver", "./BrowserDrivers/IEDriverServer.exe"));
            driver = new InternetExplorerDriver(cap);
            this.driver.manage().deleteAllCookies();
            this.driver.manage().timeouts().implicitlyWait(WaitTimeConstants.WAIT_TIME_LONG, TimeUnit.SECONDS);

            this.driver.get("yourApplication.com");
            this.driver.manage().window().maximize();

public WebDriver driver, driver1;
System.setProperty("webdriver.ie.driver", System.getProperty(
                "webdriver.ie.driver", "./BrowserDrivers/IEDriverServer.exe"));
        driver1 = new InternetExplorerDriver(cap);
        this.driver1.manage().deleteAllCookies();

        this.driver1.get("http://www.google.com");
        this.driver1.manage().window().maximize();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24746777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档