html - 我需要 CSS 选择器来选择包含给定文本的元素

标签 html css selenium selenium-webdriver

线路:

<div class="btn btn-second-in-pair-not-desired btn-tall">Clear search</div>
<div class="btn btn-second-in-pair-not-desired btn-tall">Raw Search</div>
<div class="btn btn-second-in-pair-not-desired btn-tall">Basic Search</div>
<div class="btn btn-primary-stand-alone btn-tall search-btn">Search</div>

这是我到目前为止尝试过的 - ".btn:contains('Clear search')"但 selenium 无法捕获它

最佳答案

CSS 选择器不再支持 :contains()。您必须使用 XPath "//div[text()='Clear search']"

关于html - 我需要 CSS 选择器来选择包含给定文本的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36862270/

相关文章:

CSS flexbox 交替行颜色

html - 如何在标准 html 中显示文本

java - 如何捕获 Selenium 测试异常?

javascript - 如何使用 Protractor 中的特定功能运行某些套件

html - 中间的 CSS 裁剪字符串

Javascript 覆盖 CSS 样式不适用于关键帧动画

CSS 在打印 View 中被忽略

python - 如何单击 SVG 元素?

javascript - 我应该在哪里放置 javascript 和 html 代码以便通过 JavaFX 中的 Plotly.js 进行绘图?

php - 滚动条区域在 Chrome 中只是蓝色的