从这个页面:
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:消息:无法执行 定位元素: { “方法”: “的xpath”, “选择器”: “// * [@ ID = \” ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl \ “] /跨度”} 堆栈跟踪:
答案 0 :(得分:1)
有一个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)
<强>被修改.. 强>
点击Search Permits
以对已打开的表单执行操作后,您应尝试以下操作: -
driver_1.switch_to.default_content()
driver_1.switch_to_frame("ACAFrame")
# now find your desire element
希望它能奏效...... :)