0

I want to click on the Next-button at https://free-proxy-list.net/. The XPATH selector is //*[@id="proxylisttable_next"]/a

I do this with the following piece of code:

element = WebDriverWait(driver, 2, poll_frequency = 0.1).until
(EC.visibility_of_element_located((By.XPATH, '//*[@id="proxylisttable_next"]/a')))
    if (element.is_enabled() == True) and (element.is_displayed() == True):
        element.click()
        print "next button located and clicked" # printed in case of success

Subsequently, I get all the IPs from the table like this:

IPs = WebDriverWait(driver, 2, poll_frequency = 0.1).until
(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ':nth-child(n) > td:nth-child(1)')))

Although the CSS_selector is the same for all tabs, and although I get a next button located and clicked, the IPs output is the same for both tabs (i.e. it seems like the Next-button never was clicked). Additionally, there is no Exception thrown.

Therefore, there must be something fundamentally wrong with my approach.

How to click on visible & enabled buttons correctly in phantomJS using python/selenium?

For your understanding, here is the html of the page section I am referring to:

Target HTML

4
  • 1
    post if you are getting any error Commented Feb 5, 2018 at 4:58
  • just updated - there is no Exception of any kind thrown Commented Feb 5, 2018 at 4:59
  • then the element is not clickable. Wait for some time if there is any kind of hidden lay-over. or use driver.execute_script Js will do it for you. Commented Feb 5, 2018 at 5:04
  • @PrakashPalnati if the element is not clickable, why does the above code return "next button located and clicked" Commented Feb 5, 2018 at 5:09

2 Answers 2

1

As far as I see there could be two possible causes:

  1. The click was not registered, though this is highly unlikely. You can look at other ways to click like JavascriptExecutor's click.

  2. (Most likely) The find elements are queried right after the click is performed and before the Page 2 results are loaded. Since elements is visible from page 1, it exits immediately with the list of elements from page 1. An ideal way of doing this would be (using psuedocode as I am not familiar with python)

    a. Get the current page number

    b. Get all the IPs from the current page

    c. Click Next

    d. Check if (Current page + 1 ) page has become active (class 'active' is added to the Number 2)

    e. Get all the elements from the current page

Sign up to request clarification or add additional context in comments.

1 Comment

Following your suggestions, i tested if the element is enabled, which returned a StaleElementReferenceException - I will move to the driver.execute_script-part suggested by Prakash Palnati
0

I am the OP and for anyone coming across a similar problem - The Next element was no longer attached to the DOM following its selection, which caused StaleElementReferenceException when printing element.is_enabled() or when clicking it - a detailed solution can be found here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.