python - 无法找到带有 selenium 的按钮 'ctl00'

标签 python selenium

从此页面:

https://permits.losgatosca.gov/CitizenAccess/default.aspx

我正在尝试按“建筑许可证”下的“搜索许可证”按钮。

这是它的 xpath:

//*[@id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]/span

这是我正在使用的代码:

url = "https://permits.losgatosca.gov/CitizenAccess/default.aspx"


driver_1 = webdriver.Firefox()
driver_1.get(url)

NEXT_BUTTON_XPATH = '//*[@id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]/span'
# "//*[@id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]/span"
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=\"ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl\"]/span"} Stacktrace:

最佳答案

有一个 id 为 ACAFrame 的框架,您需要先切换该框架,如下所示:-

driver_1.switch_to_frame("ACAFrame")
NEXT_BUTTON_XPATH = '//*[@id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]/span'
button = driver_1.find_element_by_xpath(NEXT_BUTTON_XPATH)

已编辑..

点击搜索许可对打开的表单执行操作后,您应该尝试如下操作:-

driver_1.switch_to.default_content()
driver_1.switch_to_frame("ACAFrame")
# now find your desire element 

希望它能起作用......:)

关于python - 无法找到带有 selenium 的按钮 'ctl00',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38099082/

相关文章:

python : Using Decorators to write Logs on a file

python - 为什么 `datetime.strptime` 得到的 2015 年第 0 周星期二的日期不正确?

javascript - 未捕获错误 : process. 不支持绑定(bind)(browserify+selenium-webdriver)

selenium - 如何在 XPath 中使用索引

python - 在 Linux 上使用 selenium chromedriver 和 python 与 chromium

java - 无法在 Selenium Java 中找到图像 xpath

javascript - Selenium 返回而不刷新

python - 计算不同颜色的像素 - Python

python - 正则表达式在 Python 中拆分单词

python - Python 上的 Webrtc 无法更改对等点之间的 ICE 连接状态