gpt4 book ai didi

java - 即使在表中等待也无法找到元素

转载 作者:太空宇宙 更新时间:2023-11-04 12:55:39 25 4
gpt4 key购买 nike

我正在尝试设置一个 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"));

这是错误:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"xpath","selector":"//table[id='MenuTable']/tbody/tr/td"}
Command duration or timeout: 36 milliseconds
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html

最佳答案

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

因此,您将收到 NoSuchElementException。因此,请确保添加@id

关于java - 即使在表中等待也无法找到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35417532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com