selenium报错Unable to find element on closed window

hubiandexiaoyu 2015-11-05 03:35:20
selenium集成webdriver开发,提示错误:
org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window
但是实际上我的浏览器并未关闭,所做的操作是更新了地址栏中的url地址,

在网上搜索到有人说是IE11的问题,换做firefox可以修复问题,但问题是我必须用IE11,哪位大牛能帮忙解答下,不胜感激。

代码如下:

WebDriver driver = new InternetExplorerDriver(srvc);
driver.navigate().to(Constraint.homepage);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);

driver.navigate().to(Constraint.homepage_cn);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);
WebElement txtbox = driver.findElement(By.xpath("/html/body/div/div[2]/a[2]"));
txtbox.click();
...全文
1750 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
MOZYOT 2018-11-08
  • 打赏
  • 举报
回复
试试这段,我也是在网上找了好久,普通的方法都试过不行,后来发现窗口时关闭之后再打开的,窗口的句柄变化了,webdriver找不到原来的窗口了 //Store the current window handle String winHandleBefore = driver.getWindowHandle(); //Perform the click operation that opens new window //Switch to new window opened for(String winHandle : driver.getWindowHandles()){ driver.switchTo().window(winHandle); } // Perform the actions on new window https://stackoverflow.com/questions/31134408/unable-to-find-element-on-closed-window-on-ie-11-with-selenium
什么都不能 2017-12-27
  • 打赏
  • 举报
回复
这种东西也要用java写?用python不是更适合吗?
longincsdn 2017-12-27
  • 打赏
  • 举报
回复
浏览器inter选项,点击安全选项卡,里面有个受信任站点,把url添加进去,允许级别调到最低
bkdxiaohui2 2017-07-30
  • 打赏
  • 举报
回复
System.setProperty("webdriver.ie.driver", "F:\\driver\\IEDriverServer.exe"); DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer(); ieCaps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.baidu.com/"); WebDriver driver = new InternetExplorerDriver(ieCaps); 初始化一个网址就可以正常使用了!
wendyzhi125 2017-06-02
  • 打赏
  • 举报
回复
楼主,解决了吗?我遇到同样的问题,改了注册表,以管理员启动仍然不行啊
qq_37852347 2017-03-10
  • 打赏
  • 举报
回复
能问下IE8遇到这种情况怎么处理呢?谢谢
souchy 2017-02-23
  • 打赏
  • 举报
回复
System.setProperty("webdriver.ie.driver", "F:\\driver\\IEDriverServer.exe"); DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer(); ieCaps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.baidu.com/"); WebDriver driver = new InternetExplorerDriver(ieCaps); 初始化一个网址就可以正常使用了!
yanhurenjian 2017-02-09
  • 打赏
  • 举报
回复
解决了吗LZ???
yanhurenjian 2017-02-09
  • 打赏
  • 举报
回复
我能说用你的方法,刚修改完后第一次是可以用的,但是我设置IE为(最开始的时候打开新页面会跳转到其他浏览器去)默认浏览器后重启了个电脑然后就又报之前的错误了。。。我也不明白为什么。。。
引用 2 楼 qulinhong 的回复:
用我的方法,我刚刚解决这个问题呢(看不懂就用google翻译一下,很容易懂得) 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. 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. For 64-bit Windows: The key is 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.
wtsos 2016-11-22
  • 打赏
  • 举报
回复
引用 2 楼 qulinhong 的回复:
用我的方法,我刚刚解决这个问题呢(看不懂就用google翻译一下,很容易懂得) 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. 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. For 64-bit Windows: The key is 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.
注册表里加了,还是报错啊
qulinhong 2016-07-07
  • 打赏
  • 举报
回复
用我的方法,我刚刚解决这个问题呢(看不懂就用google翻译一下,很容易懂得) 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. 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. For 64-bit Windows: The key is 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.
nicolas_li 2015-12-14
  • 打赏
  • 举报
回复
哈哈 我也遇到同样问题了 但没找到答案呢 找到了 互相告诉下 QQ6541139

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧