python - 使用 Python 和 Selenium 单击

标签 python selenium

我在页面中有以下元素,我需要使用 Python 和 selenium 脚本选择内部值为 18 的元素。这是第二个链接。这是页面的 HTML 代码

<a class="ui-state-default ui-state-highlight ui-state-active" href="#">17</a>
<a class="ui-state-default ui-state-highlight ui-state-active" href="#">18</a>
<a class="ui-state-default ui-state-highlight ui-state-active" href="#">19</a>

我正在尝试使用以下Python和Selenium代码来单击

elem = driver.find_element_by_xpath('//a[@class="ui-state-default"]').click()

但这不起作用。我该如何修复它?

最佳答案

elem = driver.find_element_by_link_text("18")
elem.click()

关于python - 使用 Python 和 Selenium 单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47354805/

相关文章:

python - R中的生成器函数

python - 使用 scipy.stats.kstest 进行两样本 Kolmogorov-Smirnov 检验

python - 使用 Anaconda 时使用默认的 Python

node.js - 扩展 selenium webdriver js

python selenium send_keys等待

python - 导入错误 : DLL load failed while importing pyexpat: The specified module could not be found

python - python中列表推导或生成器表达式的续行

java - Selenium Webdriver startWith() 方法在 Java 中不起作用

java - 如何使用 Selenium 为 Firefox 和 Chrome 禁用推送通知?

selenium - 将 Selenium 测试与 tfs 集成