【问题标题】:Unable to locate Element even with waits in table即使在表中等待也无法找到元素
【发布时间】:2016-02-15 19:29:14
【问题描述】:

我正在尝试设置一个 WebElement,以便我可以点击它:

executor.executeScript("arguments[0].click();", WebElement);

但是当我尝试查找元素时,它只是不断抛出无法定位元素,我尝试了几种方法,但它不会找到它。

这是元素的 HTML 路径 (td#tab_6)

<table id ="menuHolderTable" class="menuGolderTable">
  <tbody>
   <tr>
    <td id="MenuGolderCell" class="MenuHolderCell">
     <table id="MenuTable"class="MenuTable">
      <tbody>
       <tr>
        <td id="tab_6" class="tab_6">
        </td>
       </tr>
      </tbody>
    </table>
   </td>
 </tr>
</tbody>

这是我的代码:

wait.until(ExpectedConditions.not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[contains(text(),'Loading...')]"))));
WebElement toolTab = driver.findElement(By.xpath("//table[@id='MenuTable']/tbody/tr/td"));

这是错误:

线程 "main" org.openqa.selenium.NoSuchElementException 中的异常:无法找到元素:
{"method":"xpath","selector":"//table[id='MenuTable']/ tbody/tr/td"}
命令持续时间或超时:36 毫秒
有关此错误的文档,请访问:
http://seleniumhq.org/exceptions/no_such_element.html

【问题讨论】:

标签: java selenium-webdriver


【解决方案1】:

您似乎在这个特定的 LOC 中错过了 @, WebElement toolTab = driver.findElement(By.xpath("//table[id='MenuTable']/tbody/tr/td"));

因此你得到 NoSuchElementException。 所以请确保你添加 @id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-03
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多