selenium-webdriver - 无法使用 position()、last()、[1] indexing([1]--eg.) 找到 xpath 如下:兄弟姐妹、孩子、父母 没有任何工作
问题描述
我正在尝试找出 XPATH。我得到一个元素的 30 个匹配项。
我尝试使用 last()、position()、indexing[]、child、parent、following:siblings、previous:siblings,absolute XPATH 也不起作用,如何实现这一点。
<div data-reactid=".0.0.1.0.0.1.$termsConditions-component.0.1.3.1.0.0.0.0.0.2.0:$5.5.0"><span class="cursor" data-reactid=".0.0.1.0.0.1.$termsConditions-component.0.1.3.1.0.0.0.0.0.2.0:$5.5.0.0"><svg viewBox="0 0 16 20" class="excel-document" style="background-image:none;background-position:0% 0%;display:inline;fill:#333;height:20px;width:16px;" data-reactid=".0.0.1.0.0.1.$termsConditions-component.0.1.3.1.0.0.0.0.0.2.0:$5.5.0.0.0"><path d="M2 0C.9 0 .01.9.01 2L0 18c0 1.1.89 2 1.99 2H14c1.1 0 2-.9 2-2V6l-6-6H2zm7 7V1.5L14.5 7H9zm-2.34 7.39l-3.45-5.1h2.73l2.1 3.42 2.175-3.42h2.58L9.36 14.405 13.095 20H10.29l-2.34-3.705L5.565 20h-2.64l3.735-5.61z" fill="#11764B" data-reactid=".0.0.1.0.0.1.$termsConditions-component.0.1.3.1.0.0.0.0.0.2.0:$5.5.0.0.0.0"></path></svg></span>
解决方案
如果您尝试访问给定 xpath 的第一个匹配元素,则将整个 xpath 包装起来(),然后提供如下所示的索引。
第一个匹配元素:
(//span[@class='cursor']//*[local-name()='svg'][@class='excel-document'])[1]
跟随元素到第一个匹配的元素:
(//span[@class='cursor']//*[local-name()='svg'][@class='excel-document'])[1]/following-sibling::*
最后一个元素:
(//span[@class='cursor']//*[local-name()='svg'][@class='excel-document'])[last()]
推荐阅读
- ruby-on-rails-6 - 创建 ruby-on-rails 插件以获取我们在您的链接帐户中搜索的linkedin个人资料数据
- for-loop - 对 i 和 j 使用 for For 循环
- sql - 通过基于另一列值递增一列来生成唯一值
- xamarin.forms - 如何将 VSTS 内部版本号设置到应用中心
- reactjs - Ant 设计确认模式没有在单击是和否时关闭
- reactjs - Material UI:在侧边栏中使字体变大
- php - 动态填充两个 Gravityform 选择菜单
- laravel - 你好!Flutter中如何实现分页,
- python - 什么是“./sandbox 目标帐户列表”的 py-algorand-sdk 等效项
- angular - 错误:在反应形式中使用自定义跨字段验证器时,预期验证器返回 Promise 或 Observable