【问题标题】:Element is no longer attached to the DOM - for a Button元素不再附加到 DOM - 对于按钮
【发布时间】:2013-10-31 02:52:23
【问题描述】:

问题 - 获取“元素不再附加到 DOM”

接近 - 1.检查元素是否显示在网页上 2.尝试点击元素

代码 -

System.out.println("boolean value of Confirm order is" +driver.findElement(By.id("confirmOrder")).isDisplayed());
if (driver.findElement(By.id("confirmOrder")).isDisplayed() == true) {          driver.findElement(By.id("confirmOrder")).click();
//driver.findElement(By.id("confirmOrder")).sendKeys("{Enter}");
//actions.moveToElement(driver.findElement(By.id("confirmOrder"))).build().perform();
//actions.click().perform();
System.out.println("button clicked");
}

输出 确认订单的布尔值是true 点击按钮

尝试了几种方法,但似乎都没有奏效。任何帮助表示赞赏。

【问题讨论】:

  • 也试过了:-{driver.findElement(By.xpath("//input[@id='confirmOrder' and @class='confirmOrder']")).click();}
  • 哪一行会引发“元素不再附加到 DOM”?
  • @alexander-petrovich - 我没有得到下面这种方法的错误,但按钮都没有被点击:--'System.out.println("通过 xpath 搜索的按钮的布尔值是" +driver.findElement(By.xpath("//input[@id='confirmOrder' and @class='btn btnPrimary']")).isDisplayed());' driver.findElement(By.xpath("//input[@id='confirmOrder' and @class='btn btnPrimary']")).click();

标签: selenium webdriver


【解决方案1】:

我认为您没有使用隐式或显式等待,refer this 了解更多信息,对此问题提供了非常简洁的解释...

【讨论】:

    【解决方案2】:

    在 Windows 7 上,使用以下代码行无法单击某些 Web 元素(例如按钮):- driver.findElement(By.id("ButtonID")).click();

    也尝试过使用 XPath,但过去并不总是有效。

    以下是列出 Windows 7 问题的线程:https://code.google.com/p/selenium/issues/detail?id=6112

    这是解决方法:-

    WebElement element = driver.findElement(By.id("ButtonID"));
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", element);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      • 2014-06-06
      • 2014-10-05
      • 1970-01-01
      • 2021-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多