javascript - Python Selenium 在动态网页上选择复选框

标签 javascript python selenium checkbox web-scraping

我尝试了几个代码片段,但发现它们不适合我。另外,我检查并发现尝试选择的元素具有 ID,因此

find_element_by_id

没用。我也尝试过

find_element_by_xpath and find_elements_by_name

他们都不起作用。我希望能够选中 this website 上的复选框

我的代码如下所示:

from selenium.webdriver.common.keys import Keys

url = "the web page above"

# Creates an instance driver object for chrome browser...
driver = webdriver.Chrome()

# Get the url
driver.get(url)
driver.maximize_window()

# Find list elements by id and click/select on it....
driver.find_element_by_xpath(".//*[contains(text(), 'Osborne & Little')]").click()

最佳答案

您使用的 xpath 错误。 转到 chrome->检查-> cmd+F 您可以尝试放入 Xpath 来测试选择元素

给你举个例子

      <span class="tss-label tss-label--hierarchy ng-binding" ng-class="displayRow[instance.item.id] ? 'tss-hierarchy__selectedStateText' : ''" ng-bind="instance.item.alias" title="Node-1: Instance #1 - d07f2ec4-71f1-4ae0-81c6-955c86e14c6e">Node-1: Instance #1</span>

可以通过

选择
      xpath "//*[contains(@title,'Node-1: Instance #1')]

关于javascript - Python Selenium 在动态网页上选择复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41005133/

相关文章:

python - all() 与具有中断性能的 for 循环

javascript - Firefox 扩展 : close event on popup

javascript - Mongoose : "Invalid schema configuration : ' model' is not a valid type within the array"

javascript - 无法缩放 d3 techanjs

Python递归生成器性能

java - RSelenium - Java 启用

javascript - 如何从 firebase 在 Push Key 上添加数据?

javascript - 我无法从 PHP 中执行 pdf 生成 python 命令

c# - Selenium C# try/catch 请提供帮助

java - 在没有浏览器焦点的情况下自动将文件上传到站点