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();
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();
解决方案 »
- timer.schedule 不能配置按月执行 哪位ggjj帮帮忙
- fckeditor问题
- extjs combox 使用了样式后,下拉箭头与文本框错位显示
- 服务器启动就报这个错???求高手解答
- 请问可以往javascript函数中传两个变量吗
- 高分求解jsp中怎样在页面中显示excel文件啊
- ★★<jsp:forward>怎么无法用??★★
- 有没有将torque用到实际项目中的朋友,欢迎加入讨论
- 谁指点一下,在哪找到带源代码的JAVA写的树
- 使用Hibernate注解配置出错!
- 初学,问个struts2关于action名字的问题
- myeclipse运行程序,浏览器出现的地址localhost位置是一些乱东西!
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.
DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer();
ieCaps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.baidu.com/");
WebDriver driver = new InternetExplorerDriver(ieCaps);
初始化一个网址就可以正常使用了!
DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer();
ieCaps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.baidu.com/");
WebDriver driver = new InternetExplorerDriver(ieCaps);
初始化一个网址就可以正常使用了!
//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