gpt4 book ai didi

python - 如何使用面向异常的 text() 定位元素(selenium + python)?

转载 作者:行者123 更新时间:2023-12-03 15:45:44 25 4
gpt4 key购买 nike

HTML

<span class="menu-text">Download App</span>

我的定位元素的代码

driver.find_element_by_css_selector("//span[contains(text(),'App')]")

driver.find_element_by_css_selector("//span[contains(.,'App')]")

当我运行它时,报告了一个异常:

selenium.common.exceptions.InvalidSelectorException: Message: Given css selector expression "//span[contains(text(),'App')]" is invalid: InvalidSelectorError: '//span[contains(text(),'App')]' is not a valid selector: "//span[contains(text(),'App')]"

最佳答案

由于您使用的是 xpath 表达式,因此请改用 driver.find_element_by_xpath

driver.find_element_by_xpath("//span[contains(text(),'App')]")

希望对你有帮助

关于python - 如何使用面向异常的 text() 定位元素(selenium + python)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59278150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com