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
原创粉丝点击