python - 在 webapps 中查找按钮的 Xpath [Selenium]

标签 python selenium-webdriver

我正在使用 selenium 浏览此页面:

https://webapps.cityofchicago.org/activegcWeb/

但是我找不到如何移动到任何页面,使用 chrome 我得到了“下一个”按钮的 Xpath:

'//*[@id="id2"]/a[3]'

我正在使用此代码:

url = 'https://webapps.cityofchicago.org/activegcWeb/'
driver_1 = webdriver.Firefox()
driver_1.get(url)
content = driver_1.page_source

next_button_xpath = '//*[@id="id2"]/a[3]' 
button = driver_1.find_element_by_xpath(next_button_xpath)
button.click()

但是我收到了这个错误:

'selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//*[@id=\"id2\"]/a[3]"}'

最佳答案

使用 XPath 定位器“//a[contains(@href, 'headerPaginator:next')]”,然后单击。

关于python - 在 webapps 中查找按钮的 Xpath [Selenium],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36141442/

相关文章:

python - 使用 Selenium/Python 的 CSS 选择器中的 OR 条件

php - 如何使用 phpunit_selenium2 扩展执行双击?

python - Selenium webdriver 功能未显示在 pycharm 自动建议列表中

c# - 通过 web api 调用启动 web 驱动程序 chrome 浏览器

python - Anaconda 3 Spyder 似乎导致 Windows 10 上的互联网中断

java - 执行功能文件时控制台不显示任何打印输出

python - 关于python中的def和return函数

python - 如何将 SVG 折线转换为 Quickdraw Stroke-3 numpy 格式?

python - 无法使用 pip 安装 lxml

python - Python-OpenCV清除模糊的图像