NoSuchWindowException:Unable to find element (on closed window)/(with xpath)

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值