1
votes

From this page:

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

I'm trying to push the 'Search Permits' button under Building Permits.

This is its xpath:

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

This is the code I'm using:

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()

But I get this message:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//*[@id=\"ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl\"]/span"} Stacktrace:

1
"This is its xpath". How do you know that is the right xpath? - RemcoW
id="span_link_0" or #span_link_0 - dot.Py
This is not it's xpath. Check page source again - Tomasz Plaskota
@RemcoW I'm getting the Xpath with chrome. It could be wrong - Luis Rramirez
It's inside a frame.. you need to switch that frame first than go to find element like driver_1.switch_to_frame("ACAFrame") - Saurabh Gaur

1 Answers

1
votes

There is a frame with id ACAFrame, you need to switch that frame first as below :-

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)

Edited..

After clicking Search Permits to perform action on opened form you should try as below :-

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

Hope it will work...:)