如何使用Selenium WebDriver(Java)通过文本选择Web元素

如何使用Selenium WebDriver(Java)通过文本选择Web元素

问题描述:

我需要在网页上找到以下元素

I need to find the following element on the web page

<div class="b-datalist__item__addr">noreply@somedomain.com</div>

我用Java为Selenium WebDriver编码。

需要准确的CSS选择器以使用它与 driver.findElement(By.cssSelector(the-selector).click 命令。

div [class ='b-datalist__item__addr'] 选择器不够好,因为我必须根据 noreply@somedomain.com 搜索不是链接,所以我不能使用 findElement(By.linkText())命令。

I'm coding with Java for Selenium WebDriver.
Need the exact CSS selector for this element to use it with driver.findElement(By.cssSelector(the-selector).click command.
div[class='b-datalist__item__addr'] selector is not good enough since I must search according to noreply@somedomain.com text that is not a link so I can't use findElement(By.linkText()) command.

Css不允许您进行文字搜索。 是唯一的选项。

Css does not allow you do text based search. xpath is the only option there.

//div[contains(text(),'noreply@somedomain.com')]