【问题标题】:How to click the element from the table Search by specific text如何单击表格中的元素按特定文本搜索
【发布时间】:2019-05-29 07:46:44
【问题描述】:

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

HTML:

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

我想点击这个&lt;tr&gt;,里面有文字Shelton

【问题讨论】:

  • 您的代码丢失
  • 我想用文本选择

标签: java selenium xpath webdriverwait xpath-1.0


【解决方案1】:

所需元素是 Angular 元素,以便定位和 click() 您必须诱导 WebDriverWait 元素以使 元素可点击 的元素,您可以使用以下任一Locator Strategy:

  • xpath1:

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

    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();

【讨论】:

  • 我使用了 Thread.sleep();但它没有工作..无论如何你的代码工作非常感谢
  • 我有另一个查询,我想将此值存储在变量 new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='align-中间 cursorPoint' 和 text()='Shelton']"))).click();所以我可以用整个表格搜索这个文本
  • @ArjunBharadwaj 不,我们不是存储变量,而是同时定位和调用click()。用步骤检查更新的答案。
  • 是的,我理解,但是如何通过表格检查文本值
  • 您能就您的新要求提出一个新问题吗?
猜你喜欢
  • 2018-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-18
  • 1970-01-01
  • 2018-12-10
相关资源
最近更新 更多