Python selenium xpath的后裔 您所在的位置:网站首页 python点击按钮 Python selenium xpath的后裔

Python selenium xpath的后裔

2023-03-25 02:27| 来源: 网络整理| 查看: 265

Why these one don't work :

//button[@class='wpO6b ']/descendant::svg[@aria-label='Like'] //button[@class='wpO6b ']//svg[@aria-label='Like']

你选择的是svg元素而不是按钮。你必须把svg部分放在一个谓词里面。

//button[@class='wpO6b' and descendant::svg[@aria-label='Like']]

这个几乎是好的,但由于在class属性的button元素中有一个空格,所以它不会工作。它可以用contains函数进行相应的修复,这是一个更安全的选择。

//button[contains(@class,'wpO6b') and descendant::svg[@aria-label='Like']]

另一种选择按钮的方法(使用ancestor轴和更强大的谓词)。

//svg[@aria-label="Like" and @fill="#262626"]/ancestor::button[1][contains(@class,"wpO6b")]

如果你要处理的是namespaces,请使用以下表达方式。

//*[local-name()='button'][contains(@class,'wpO6b') and descendant::*[local-name()='svg'][@aria-label='Like']]


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有