css - selenium xpath 获取没有关联 id 的元素的值

标签 css selenium xpath selector

我想从以下 selenium 代码中获取值 606

<div class="price pad-15 per-person budget-pp marg-left-10 ">
<span>From</span>
<h2 class="size-28 dis-inblock">
<span class="size-22">£</span>
606
</h2>
<span>Per person</span>
</div>

任何人都可以帮助我识别值 606 的 xpath。提前致谢。

最佳答案

包含 606 的元素的

XPath 是:

//h2[span[text()="£"]]

您可以使用编程语言中的适当方法获取值(例如 .get_attribute("text")Python 中的 .text' )

如有任何问题请告诉我

关于css - selenium xpath 获取没有关联 id 的元素的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39975881/

相关文章:

javascript - css悬停颜色过渡循环

python - 尝试使用 selenium 和 python 登录网页时出错

xpath - 我可以将 xpath 2.0 与 firefox 和 selenium 一起使用吗?

JQuery Tabs - 页面内容加载的样式问题

html - 强制在 Jekyll 中使用绝对 URL

css - 为什么 Google Chrome 浏览器使用 -webkit-* 前缀,而 Chrome 运行在 Blink 上(IOS 除外,它们运行在 webkit 上)

selenium - 如何通过 docker-compose 而不是使用 docker 启动 selenium hub 和一个链接节点?

java - Selenium WebDriver dom 定位器解决方法

xpath - 测试自动化框架提供了哪些我使用 Selenium Webdriver 编写脚本的方法没有提供的功能?

php - 如果元素具有 xmlns 属性,则 Xpath 失败