3

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
HolyMonk
  • 432
  • 6
  • 17
  • Is it complete exception log? Can you share page `URL`? – Andersson May 10 '17 at 20:25
  • URL: https://en.camping.info/campsites – HolyMonk May 10 '17 at 20:26
  • added the exception log and URL to the question – HolyMonk May 10 '17 at 20:28
  • Try adding `driver.find_element_by_id("btn-consent").click()` before clicking on the page buttons. I have a feeling the cookie info bar is covering up the the page buttons. – Dean W. May 10 '17 at 20:43
  • When I do: driver.get("https://en.camping.info/campsites") driver.find_element_by_id("btn-consent").click() element = driver.find_element_by_id("ctl00_ctl00_cphMain_main_ucSearchResult_rptPager_ctl01_btnPageNumber") element.click() I get the exact same error. – HolyMonk May 10 '17 at 20:46

2 Answers2

2

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()
Andersson
  • 51,635
  • 17
  • 77
  • 129
2

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

  1. Element is not visible or shown
  2. Element has an overlay over it
  3. Element is generated after the page is refreshed (Meaning it's not visible for a few seconds then it shows)

Great StackOverflow Explaining this

HERE


Community
  • 1
  • 1
innicoder
  • 2,612
  • 3
  • 14
  • 29
  • Will surely check this out, but you've been beaten by Mr. Andersson by a few minutes to be the accepted answer. – HolyMonk May 10 '17 at 21:01
  • Yeah, awesome guy. He's diagnosed the problem and got a fix to it, his method is way better but requires a little bit more explanation (that'd be nice if he added some comments/documentation to what he's done since it might be confusing to someone that doesn't understand what's going on. Great question too Monk, keep it up! – innicoder May 10 '17 at 21:03