如何使用Selenium WebDriver(Java)通过文本选择Web元素 [英] How to select a web element by text with Selenium WebDriver, Java

查看:545
本文介绍了如何使用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')]

这篇关于如何使用Selenium WebDriver(Java)通过文本选择Web元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆