python - 带有部分字符串的 xpath 搜索属性

标签 python xpath selenium-webdriver

我正在搜索类似 find_element_by_xpath('//a[@href="/requirements/22"]')

的元素

我可以只搜索其中的一部分吗?我的意思是不是 /requirements/22*22?

最佳答案

包含:

find_element_by_xpath('//a[contains(@href, "22")]')

开始于:

find_element_by_xpath('//a[starts-with(@href, "22")]')

结束于:

find_element_by_xpath('//a[starts-with(@href, "22")]')

您也可以自由尝试组合,示例: find_element_by_xpath('//a[开始于(@href, "22") 并包含(@href, "req")]')

关于python - 带有部分字符串的 xpath 搜索属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35517437/

相关文章:

python - 如何在 Mac OS Sierra 上使用 Virtualenv 安装 PyGreSQL

selenium - Selenium IDE 中的 XPATH : Matching text in a <td> tag that contains <br> tags

c# - driver.Manage().Logs.GetLog(LogType.Browser) 在 Chromedriver 版本 75.0.3770 中不再工作

javascript - 如果 "value"属性为 "type",如何设置 "number"属性

javascript - 我们可以将正则表达式放在 Protractor 的 exports.config 的 seleniumServerJar 中吗

python - Django ImportError : No module named tango_with_django_project. 设置

python - 高斯 SVM 参数 C 和 gamma

python - 请求 - 获取内容类型/大小而不获取整个页面/内容

Perl Xpath : search item before a date year

web-applications - Selenium IDE 1.9.1 xpath 包含选择