gpt4 book ai didi

java - 如何单击表格中的元素 按特定文本搜索

转载 作者:太空宇宙 更新时间:2023-11-04 09:37:17 26 4
gpt4 key购买 nike

如何单击表中文本的元素搜索。我尝试了一些代码,但它不起作用。

HTML:

<td _ngcontent-c8="" class="align-middle cursorPoint" tabindex="0">Shelton</td>

我想点击这个<tr>其中包含文本谢尔顿

最佳答案

所需的元素是 Angular元素,以便找到并 click() 元素,您必须引发 WebDriverWait 才能使 元素可点击,并且您可以使用以下任一 Locator Strategy :

  • xpath 1:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='align-middle cursorPoint' and text()='Shelton']"))).click();
  • xpath 2:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[text()='Shelton']"))).click();
<小时/>

更新

要逐步实现相同目标:

WebElement elem = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='align-middle cursorPoint' and text()='Shelton']")));
elem.click();

关于java - 如何单击表格中的元素 按特定文本搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56355469/

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