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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31134408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 10:41:35  来源:igfitidea点击:

Unable to find element on closed window on IE 11 with Selenium

javainternet-explorerselenium-webdriverautomated-testsinternet-explorer-11

提问by Alex

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

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

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)

启动 InternetExplorerDriver 服务器(64 位)2.46.0.0 侦听端口 43760 线程“main”org.openqa.selenium.NoSuchWindowException 中的异常:无法在关闭的窗口上找到元素(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:15 毫秒构建信息:版本:'2.46.0',修订版:'61506a4624b13675f24581e453592342b7485d71',时间:'2015-06-04 10:22:50',系统 ip:'用户 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,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}] 会话 ID:8a5b7ab5-862a-462d-ab4b-929d4ed5b71a ***s 元素名称,{U =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(未知来源)在 org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204) 在 org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) 在 org.openqa.selenium.remote。 RemoteWebDriver.execute(RemoteWebDriver.java:605) 在 org。openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:358) 在 org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:431) 在 org.openqa.selenium.By$ByName.findElement(By$ByName.findElement(ByName.findElement) java:300) 在 org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:350) 在 MySel20Proj.MySel20Proj.App.main(App.java:42)

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

我试图按照https://code.google.com/p/selenium/wiki/InternetExplorerDriver上的配置教程进行操作,但仍然无法正常工作。这段代码适用于 Firefox 和 Chrome。

回答by user2771721

Try going to Internet Options --> Security --> "Enable Protected Mode" on ALLzones should either be checked or ALLunchecked.

尝试将Internet选项- >安全- >“启用保护模式”在所有的区域要么检查或全部选中。

enter image description here

在此处输入图片说明

回答by Ripon Al Wasim

There are 2 ways:

有2种方式:

Way 1:Setting INITIAL_BROWSER_URL:

方式 1:设置 INITIAL_BROWSER_URL:

File ieFile = new File("D:\IEDriverServer_x64_2.53.0\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", ieFile.getAbsolutePath());
DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer();
ieCaps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.bing.com/");
driver = new InternetExplorerDriver(ieCaps);
//some operations on that site
driver.findElement(By.id("sb_form_q")).clear();
driver.findElement(By.id("sb_form_q")).sendKeys("Ripon Al Wasim");
driver.findElement(By.id("sb_form_go")).click();

Way 2:To set a registry entry on the target computer:
For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates.

方式 2:在目标计算机上设置注册表项:
仅对于 IE 11,您需要在目标计算机上设置注册表项,以便驱动程序可以保持与它创建的 Internet Explorer 实例的连接。

For 32-bit Windows:The key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

对于 32 位 Windows:您必须在注册表编辑器中检查的项是 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。

For 64-bit Windows:The key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

对于 64 位 Windows:密钥是 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。

Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.

请注意 FEATURE_BFCACHE 子项可能存在也可能不存在,如果不存在则应创建。重要提示:在此键中,创建一个名为 iexplore.exe 且值为 0 的 DWORD 值。

For more details you can visit: https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

有关更多详细信息,您可以访问:https: //github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

回答by Manikanta Thota

For 32-bit Windows:The key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

对于 32 位 Windows:您必须在注册表编辑器中检查的项是 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。

For 64-bit Windows:The key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

对于 64 位 Windows:密钥是 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。

Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.

请注意 FEATURE_BFCACHE 子项可能存在也可能不存在,如果不存在则应创建。重要提示:在此键中,创建一个名为 iexplore.exe 且值为 0 的 DWORD 值。

Screenshot

Screenshot

回答by User6

I faced the same issue after going through every possible solution finally I got the answer.Try this it will definitely solve your problem as well.

在经历了所有可能的解决方案后,我遇到了同样的问题,最终我得到了答案。试试这个它肯定也能解决你的问题。

DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();

capabilities.setCapability(CapabilityType.BROWSER_NAME, "IE");

capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);

capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);

System.setProperty("webdriver.ie.driver","C://MavenTest//driver//IEDriverServer.exe");

driver = new InternetExplorerDriver();

回答by Addagatla Balaswamy

I had faced the similar issue. I faced while I was running my code in the Maven build. Here in the POM XML file, I had a different version whereas actual selenium installed is another version. So just changed the version so that it matches with the installed version. And Now everything working fine

我遇到过类似的问题。我在 Maven 构建中运行我的代码时遇到了问题。在 POM XML 文件中,我有一个不同的版本,而实际安装的 selenium 是另一个版本。所以只需更改版本,使其与安装的版本匹配。现在一切正常

回答by nio

Ripon Al Wasim posted this url, which is a key to IE11 working with Selenium. https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

Ripon Al Wasim 发布了这个 url,这是 IE11 与 Selenium 协同工作的关键。 https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

I had this setup:

我有这个设置:

  • Windows 7 Pro 64 bit
  • IE11 64 bit, latest I found
  • Selenium remote server 2.53.1 64 bit
  • IEDriverServer 2.53.1 64 bit
  • selenium 2.53.1 module installed on 64 bit linux machine used with 64 bit python
  • Windows 7 专业版 64 位
  • IE11 64 位,我发现的最新版本
  • Selenium 远程服务器 2.53.1 64 位
  • IEDriverServer 2.53.1 64 位
  • selenium 2.53.1 模块安装在 64 位 linux 机器上,与 64 位 python 一起使用

downloaded from here: http://selenium-release.storage.googleapis.com/index.html?path=2.53/

从这里下载:http: //selenium-release.storage.googleapis.com/index.html?path=2.53/

I had to follow the guide and to:

我必须遵循指南并:

  • Set Enhanced Protected Mode to disabled in all security zones which is a requirement for IE10 and IE11.
  • Add the FEATURE_BFCACHEkey and it's iexplore.exeDWORD into registry
  • I made all used software to be 64 bit.
  • Check that zoom in IE is set to 100%.
  • Check if size of text is 100% in Windows display settings.
  • 在所有安全区域中将增强保护模式设置为禁用,这是 IE10 和 IE11 的要求。
  • FEATURE_BFCACHE密钥和它的iexplore.exeDWORD添加到注册表中
  • 我将所有使用过的软件都设为 64 位。
  • 检查 IE 中的放大是否设置为 100%。
  • 在 Windows 显示设置中检查文本大小是否为 100%。

Additionaly:

另外:

And it worked. I divert from the guide when I specify a path to IEDriverServer.exe when I run standalone server, so it doesn't necessary have to be in the PATH.

它奏效了。当我在运行独立服务器时指定到 IEDriverServer.exe 的路径时,我会从指南中转移,因此它不必位于 PATH 中。