Trouble Clicking On The Button For The Next Page
Solution 1:
@Grasshopper has already provided with a solution, but I'll try to give more details for you to understand why your code fails
There are two links with the same HTML
code present in page source: the first is hidden, second (the one that you need) is not.
You can check it with
print(len(driver.find_elements_by_css_selector('a.ui-paging-next')))
While css-selector or XPath returns you simply the first occurence, search by link text returns link with the visible text only:
print(len(driver.find_elements_by_link_text('Next')))
That's why your find_element_by_css_selector(...)
code doesn't work, but find_element_by_link_text(...)
does.
Also note that line
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'table.fe-datatable')))
should already return you required element, so there is no need in
tab_data = driver.find_element_by_css_selector('table.fe-datatable')
Just use
tab_data = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'table.fe-datatable')))
To avoid getting StaleElementReferenceException
you should re-define your tab_data
on each iterarion as tab_data
defined on first page will not be accessible on the next page. Just put tab_data
definition inside the while
loop
UPDATE
In your code try to replace
try:
driver.find_element_by_link_text('Next').click()
except:
break
with
first_row = driver.find_element_by_css_selector('table.fe-datatable tr.odd').text
try:
driver.find_element_by_link_text('Next').click()
except:
break
wait.until(lambda driver: driver.find_element_by_css_selector('table.fe-datatable tr.odd').text != first_row)
Post a Comment for "Trouble Clicking On The Button For The Next Page"