NoSuchWindowException - Selenium 3.4.0 - IE 11

时间:2017-05-16 07:27:47

标签: selenium selenium-webdriver internet-explorer-11 selenium-iedriver selenium3

我已经推出了IE 11浏览器,

我已导航到初始网址 - >完成鼠标并点击链接 - >它会重定向到另一个页面。

在该页面中,我必须单击一个按钮,但它会抛出异常

org.openqa.selenium.NoSuchWindowException:无法在关闭的窗口中找到元素

但是屏幕仍然可用。

这是我的代码

WebElement e = driver.findElement(By.xpath(“html / body / div [2] / div / div / header / nav / ul / li [2] / a”));

    Actions a = new Actions(driver);
    a.moveToElement(e).build().perform();

    driver.findElement(By.xpath("//*[@id='menu-item-35']/a")).click();



  TimeUnit.SECONDS.sleep(5);

//此后发生异常,但是当我删除下面的代码时,测试用例传递

driver.findElement(By.xpath("//*[@id='default_products_page_container']/div[3]/div[2]/form/div[2]/div[1]/span/input")).click();

这是页面的网址:http://store.demoqa.com/

2 个答案:

答案 0 :(得分:0)

在我看来,这是一个竞争条件错误。我自己有这些情况,我实际上可以看到一个窗口,但Selenium仍然说它不在那里。

您是否尝试将睡眠时间设置为更高的值?

您也可以尝试在点击元素之前设置expect-wait-condition。

    WebDriverWait wait = new WebDriverWait(DRIVER, 20);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='default_products_page_container']/div[3]/div[2]/form/div[2]/div[1]/span/input"))

答案 1 :(得分:0)

Here is the Solution to your Question:

A few words about the solution:

  1. The xpath html/body/div[2]/div/div/header/nav/ul/li[2]/a looks petty vulnerable to me use linkText locator.
  2. Once you use Action Class to build().perform(), induce a bit of wait before locating another element.
  3. Instead of xpath locator of //*[@id='menu-item-35']/a element, use linkText locator.
  4. Again the xpath //*[@id='default_products_page_container']/div[3]/div[2]/form/div[2]/div[1]/span/input looks petty vulnerable to me use a logical uniquexpath.
  5. Here is your own working code block with some simple tweaks in it:

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    WebElement e = driver.findElement(By.linkText("Product Category"));
    Actions a = new Actions(driver);
    a.moveToElement(e).build().perform();
    driver.findElement(By.linkText("iMacs")).click();
    driver.findElement(By.xpath("//input[@name='Buy']")).click();
    

Let me know if this Answers your Question.