【问题标题】:Selenium - NoSuchWindowException in IE 11Selenium - IE 11 中的 NoSuchWindowException
【发布时间】:2014-09-04 23:22:51
【问题描述】:

我正在尝试在 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");

还有异常堆栈跟踪

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)

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

【问题讨论】:

    标签: java internet-explorer selenium browser-automation


    【解决方案1】:

    首先,不要使用

    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
    

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

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

    【讨论】:

    【解决方案2】:

    我正在使用 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 子项可能存在也可能不存在,如果不存在,则应创建它。

    重要提示:在此键中,创建一个名为iexplore.exeDWORD 值,值为0。

    【讨论】:

    • 哇,好用。但是输入速度非常慢 - 每分钟一封信:-/有什么想法吗?
    • 希望您使用的是 64 位机器和 64 位 IE 驱动程序。请改用 32 位 IE 驱动程序。
    • 我使用的是 64 位机器。添加了相关注册表项并更改为 32 位 IE 驱动程序。仍然出现异常。
    • internet explorer 中没有main
    • 请确保您在 HKEY_LOCAL_MACHINE 下导航
    【解决方案3】:

    @David Kemp 建议的解决方案 不适用于 ie 11 of windows 10 - 64 bit。我已经根据提到的步骤添加了注册表项 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-page:9443)后,它无法执行 driver.navigate().to("javascript:document.getElementById('overridelink').click()"); throwing NoSuchWindowException

    但是 同样适用于 11 个 Windows 7-64 位 并且能够执行脚本。

    让 ie 11 为 win 10 工作的解决方法是将 initialBrowserUrl 功能设置为 https://my-page:9443,如下所示

    capabilities.setCapability("initialBrowserUrl", "https://my-page:9443");
    

    但我仍然很困惑,为什么 ie11 / windows 10 不一样?

    【讨论】:

      【解决方案4】:

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

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

       HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet explorer\Main\FeatureControl\FEATURE_BFCACHE
      

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

      【讨论】:

        【解决方案5】:

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

            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();
        

        【讨论】:

          【解决方案6】:

          将 AUT 的域添加到“受信任的站点”列表中,即在“Internet 选项”中。解决了问题。

          【讨论】:

            【解决方案7】:

            IE 选项 --> 安全选项卡 -> 取消选中“启用保护模式”对我有用。

            【讨论】:

              【解决方案8】:

              在 IE11 中将 http://localhost/ 添加到您的受信任站点。这对我有用,在尝试了其他一切都没有结果之后。

              【讨论】:

                【解决方案9】:

                首先忽略...我已经在我想要的 IE 驱动程序功能中尝试了以下行,然后它的工作.. :)

                            ieCapabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL,false);
                

                【讨论】:

                  【解决方案10】:

                  您可以从以下几个选项:

                  1. 在项目中使用相对路径,以后可以选择获取其绝对路径。
                  2. 将所有的保护模式设置为启用或禁用。
                  3. 尝试理解这个异常的真正含义“org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information) 命令持续时间或超时:18 毫秒"

                  这表明您的代码(网络驱动程序)所做的任何事情都无法识别 IE 的窗口。

                  可能的原因可能是: 一种。多个驱动程序实例已经在运行,这些实例由较早的运行实例化,并且无法被quit() 终止。 湾。有时当您在驱动程序上使用 close() 时,它不会终止 IE 驱动程序,因此在 finally 块内关闭后使用 quiet()。 是的,添加一些异常处理以避免上述问题。

                  1. 异常 "org.openqa.selenium.NoSuchWindowException" 还表明 Web 驱动程序实例无法获取 IE 窗口选项卡的句柄。我偶然遇到了这个问题,浏览器已关闭,代码仍在尝试定位 Web 元素并对其执行一些操作。在这种情况下,驱动程序抛出这个异常来告诉根本没有打开IE浏览器。

                  2. 检查浏览器的打开情况也会有所帮助,我通常会保留一些代码,这些代码会记录使用的驱动程序对象及其尝试连接的端口以及连接到哪个浏览器的日志。

                  对我来说,第 4 点和第 5 点有效。但您可能只想更改网络驱动程序的服务,即浏览器。 IE 有时太慢了,无法支持 selenium API 调用:(

                  【讨论】:

                    猜你喜欢
                    • 2017-10-15
                    • 1970-01-01
                    • 1970-01-01
                    • 2018-12-17
                    • 2015-10-20
                    • 1970-01-01
                    • 2014-12-30
                    • 1970-01-01
                    • 2021-07-23
                    相关资源
                    最近更新 更多