无法使用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线程“main”中的exceptionorg.openqa.selenium.NoSuchWindowException:无法在关闭的窗口中找到元素(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:15毫秒构建信息:版本:’2.46.0’,修订版:’61506a4624b13675f24581e453592342b7485d71’,时间:’2015-06-04 10: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 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,initi alBrowserUrl = http:// localhost:43760 / ,takesScreenshot = true,javascriptEnabled = true,ignoreProtectedModeSettings = false,enableElementCacheCleanup = true,cssSelectorsEnabled = true,unexpectedAlertBehaviour = dismiss}]会话ID:8a5b7ab5-862a-462d-ab4b-929d4ed5b71a ** *元素信息:{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 at位于org.openqa.selenium.remote上的org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)的java.lang.reflect.Constructor.newInstance(未知来源).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.java:300)atAg.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:350)at MySel20Proj.MySel20Proj.App。主(App.java:42)

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

尝试进入Internet选项 – >安全性 – > 所有区域上的“启用保护模式”应选中或全部取消选中。

在此处输入图像描述

有两种方式:

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

方法2:在目标计算机上设置注册表项:
仅对于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.exe的值为0的DWORD值。

有关详细信息,请访问: https : //github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

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

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

对于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.exe的值为0的DWORD值。

截图

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

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

我有这个设置:

  • Windows 7 Pro 64位
  • IE11 64位,最新发现
  • Selenium远程服务器2.53.1 64位
  • IEDriverServer 2.53.1 64位
  • selenium 2.53.1模块安装在64位linux机器上,与64位python一起使用

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

我必须遵循指南并:

  • 在所有安全区域中将增强保护模式设置为禁用,这是IE10和IE11的要求。
  • FEATURE_BFCACHE键和它的iexplore.exe DWORD添加到注册表中
  • 我把所有使用的软件都做成了64位。
  • 检查IE中的缩放是否设置为100%。
  • 在Windows显示设置中检查文本大小是否为100%。

Additionaly:

  • 我不得不在IE中禁用代理设置,因为它阻止了Selenium remote serverIEDriverServer通信。
  • 我正在运行webdriver并将requireWindowFocus设置为true,因为由于某些超时问题导致64位selenium的密钥输入速度很慢 ( Selenium WebDriver在IE浏览器的文本字段中键入速度非常慢 )

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