I am trying to use Selenium to click a button with the following HTML code:
<a id="ctl00_ctl00_cphMain_main_ucSearchResult_rptPager_ctl01_btnPageNumber" class="pager2"href="javascript:__doPostBack('ctl00$ctl00$cphMain$main$ucSearchResult$rptPager$ctl01$btnPageNumber','')">2</a>
I can find this button by using the following code:
element = driver.find_element_by_id("ctl00_ctl00_cphMain_main_ucSearchResult_rptPager_ctl01_btnPageNumber")
but if I then do:
element.click()
I get an error message, namely:
WebDriverException: Message: unknown error: Element <a id="ctl00_ctl00_cphMain_main_ucSearchResult_rptPager_ctl01_btnPageNumber" class="pager..." href="javascript:__doPostBack('ctl00$ctl00$cphMain$main$ucSearchResult$rptPager$ctl01$btnPageNumber','')">2</a> is not clickable at point (82, 516). Other element would receive the click: <p>...</p>
(Session info: chrome=57.0.2987.133)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.10586 x86_64)
The URL I'm trying to navigate through is:
https://en.camping.info/campsites
There are 2 div elements that overlaps the pagination panel and receives the click. You might get rid of those div elements (hide them to be able to click on required button) with JavaScriptExecutor as below:
driver.get("en.camping.info/campsites")
page = driver.find_element_by_id("ctl00_ctl00_cphMain_main_ucSearchResult_rptPager_ctl01_btnPageNumber")
nav_div = driver.find_element_by_id('jq-app-buttons-wrapper')
driver.execute_script('arguments[0].style.display="none";', nav_div)
cookies_div = driver.find_element_by_id('cookie-consent-wrapper')
driver.execute_script('arguments[0].style.display="none";', cookies_div)
page.click()
Try something like this:
from selenium.webdriver.common.action_chains import ActionChains
elem = driver.find_element_by_xpath('''//*[@id="ctl00_ctl00_cphMain_main_ucSearchResult_rptPager_ctl00_btnPageNumber"]''')
#I've used xpath here instead of id you can change that.
ActionChains(driver).move_to_element(elem).click().perform()
The issue here is that either One of 3 cases
Great StackOverflow Explaining this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With