NoSuchWindowException:Unable to find element (on closed window)/(with xpath)
来源:互联网 发布:针锋对决网络剧在哪看 编辑:程序博客网 时间:2024/06/05 08:11
test ENV
- os.name: ‘Windows 10’
- os.arch: ‘amd64’
- java.version: ‘1.8.0_45’
- Explorer version: IE11
- Driver info: org.openqa.selenium.ie.InternetExplorerDriver
测试代码1
@Test public void TestDriver(){ driver.get("http://10.202.113.22:8081/cashier"); driver.findElement(By.xpath("//input[@name='policyNo']")).sendKeys("3766"); driver.findElement(By.name("query")).click(); }
测试代码2
@Test public void TestDriver(){ driver.get("http://10.202.113.22:8081/cashier"); waitPageLoad(); driver.findElement(By.xpath("//input[@name='policyNo']")).sendKeys("3766"); driver.findElement(By.name("query")).click(); } public void waitPageLoad(){ new WebDriverWait(driver, 30).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { JavascriptExecutor js = (JavascriptExecutor) driver; return (Boolean) js.executeScript("return document.readyState;").equals("complete"); } }); }
driver初始化代码
static WebDriver driver; @Before public void setup() { System.setProperty("webdriver.ie.driver", "src/main/resources/IEDriverServer.exe"); DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); driver = new InternetExplorerDriver(ieCapabilities); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().window().maximize(); } @After public void testAfter() { driver.close(); }
实际上这两个代码在使用localhost的时候
既用 driver.get(“http://localhost:8081/cashier“);
的时候,已经通过测试,但是在部署到服务器上时,上面两段代码分别报了以下错误
org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //input[@name='policyNo'] (WARNING: The server did not provide any stacktrace information)Command duration or timeout: 30.50 seconds
org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)Command duration or timeout: 264 milliseconds
解决办法
Internet Options –> Security –> “Enable Protected Mode” on ALL zones should either be checked or ALL unchecked.
参考http://stackoverflow.com/questions/31134408/unable-to-find-element-on-closed-window-on-ie-11-working-with-selenium
暂不知道导致该问题的具体原因.
0 0
- NoSuchWindowException:Unable to find element (on closed window)/(with xpath)
- Appium 报错:org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
- javascript错误解决:Unable to modify the parent container element before the child element is closed
- HTML Parsing Error: Unable to modify the parent container element before the child element is closed
- IE8报错:Unable to modify the parent container element before the child element is closed
- HTML Parsing Error:Unable to modify the parent container element before the child element is closed
- HTML Parsing Error: Unable to modify the parent container element before the child element is closed
- IE 8 HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
- IE 8 HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
- IE 8 HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
- HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
- GWT unable to find gwt.xml file on your classpath
- [!] Unable to find a pod with name, author, summary, or ...
- 关于 EntityNotFoundException: Unable to find Person with id 11
- Unable to find models.User with id xx
- yii2 Unable to find debug data tagged with
- Unable to add window
- Fix “Windows was unable to find a certificate to log you on to the network”
- LightOJ-1049-图论
- Jnetpcap 官方实例(4)- 将捕获的数据包写入文件
- python Excel转plist文件
- Error -27796: Failed to connect to server问题解决记录
- ORACLE 中汉字占几个字节?
- NoSuchWindowException:Unable to find element (on closed window)/(with xpath)
- spring mvc 防止重复提交表单的两种方法,推荐第二种
- 工作前端记录
- Python必会的单元测试框架 —— unittest
- 链式编程初探
- 数据结构-实验四 二叉树
- 昨天学了js的控制css样式,自己做了个算卦小程序
- Unity3D优化总结
- Spring源码解析的优秀文章