Selenium无法点击网页python的按钮

姆博韦

我正在尝试单击网页上的投票按钮。我可以使用我的 python 代码浏览页面并单击一个单选按钮。投票按钮未在 HTML 代码中声明为“按钮”或“输入”元素。我真的不确定如何让 Selenium 导航到它并单击它。该按钮本身不链接到网址。我试过用 Tab 键点击它,然后按回车键,但它会跳到按钮本身。我可以提供进一步的 HTML 和任何其他补充信息。HTML 的图片如下!

按钮的 HTML 代码

Shanyl Ong

试试这个:

from selenium import webdriver

driver_options = webdriver.ChromeOptions()
chromedriver = "path/to/chromedriver"

driver = webdriver.Chrome(chromedriver, options = driver_options)
driver.get("https://threerivers.okvype.com/2020/02/24/vote-now-okmulgee-area-preseason-baseball-poll-presented-by-muscogee-creek-nation-poll-ends-3-2/")
buttonpath = '//*[@id="pd-vote-button10509753"]'
dotpath = '//*[@id="PDI_answer48619888"]'
dot = driver.find_element_by_xpath(dotpath)
vote = driver.find_element_by_xpath(buttonpath)
dot.click()
vote.click()

通过选择要单击的正确元素,它对我有用。有时按钮周围有一个环绕元素,它必须接收点击而不是目标元素,以便触发响应。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章