我正在尝试设置一个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
答案 0 :(得分:0)
在这个特定的LOC中,您似乎错过了 @ , WebElement toolTab = driver.findElement(By.xpath(“// table [id ='MenuTable'] / tbody / tr / td”));
因此你得到NoSuchElementException。 因此,请务必添加 @id 。