I try to click on the next page link on this webpage: https://www.kumon.co.uk/find-a-tutor/ This page will be empty till you type a location like London, Manchester or wherever :)
The source-code looks like this:
<nav class="visible-xs-block">
<ul class="pager">
<li>
<a data-page="2" href="https://www.kumon.co.uk/find-a-tutor/?centre_search=london&page=2"><small><i class="fa fa-chevron-right"></i></small></a>
</li>
</ul>
</nav>
I try to make a click to the next page in 2 ways:
First trial:
browser.find_elements_by_xpath("//*[@class='fa fa-chevron-right']/../..")[2].click()
Error:
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
Second trial:
WebDriverWait(browser, 30).until(EC.presence_of_element_located((By.XPATH, "//*[@class='fa fa-chevron-right']/../.."[2]))).click()
Error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
What matters is that I can't find any documentation regarding the second error message, and that's why I post my first message on stackoverflow :)
FYI when I remove the click() the element is well localized so this is the click() which sucks seemingly :/
I have found out this solution dealing with Javascript which may be cool for me but I don't really know how to implement this => Selenium Element not visible exception
What do you think about it ?
Do you have any idea to help me please ? i'm stuck on this issue for 2 days unfortunately :(
EDIT:
This snippet:
while browser.find_element_by_xpath("//ul[@class='pagination']//li[last()]/a/small"):
action = ActionChains(browser)
search_button = WebDriverWait(browser, 20).until(
EC.element_to_be_clickable((By.XPATH, "//ul[@class='pagination']//li[last()]/a/small")))
action.move_to_element(search_button)
sleep(1)
search_button.click()
raises an error selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
And I'm not sure that using try...except is the best solution to solve it, is it ?
Thank's in advance, Nicolas.