python - Can't move on to the next page -


i've written script in python selenium traverse different pages staring first page through pagination. however, there no options next page button except numbers. when click on number takes me next page. anyways, when try script, click on second page , goes there doesn't slide anymore, meant instead of going on third page breaks throwing following error.

line 192, in check_response     raise exception_class(message, screen, stacktrace) selenium.common.exceptions.staleelementreferenceexception: message: stale element reference: element not attached page document 

script i'm trying with:

from selenium import webdriver selenium.webdriver.common.by import selenium.webdriver.support.ui import webdriverwait selenium.webdriver.support import expected_conditions ec  driver = webdriver.chrome() driver.get("http://www.cptu.gov.bd/awardnotices.aspx") wait = webdriverwait(driver, 10) driver.find_element_by_id("imgbtnsearch").click() item in wait.until(ec.presence_of_all_elements_located((by.css_selector, "#dgawards > tbody > tr > td > a"))):     item.click() driver.quit() 

elements within pagination numbers are:

<tr align="right" valign="top" style="font-size:xx-small;font-weight:normal;white-space:nowrap;">         <td colspan="8"><span>page: </span><a href="javascript:__dopostback('dgawards$ctl01$ctl01','')">1</a>&nbsp;<a href="javascript:__dopostback('dgawards$ctl01$ctl02','')">2</a>&nbsp;<span>3</span>&nbsp;<a href="javascript:__dopostback('dgawards$ctl01$ctl04','')">4</a>&nbsp;<a href="javascript:__dopostback('dgawards$ctl01$ctl05','')">5</a>&nbsp;<a href="javascript:__dopostback('dgawards$ctl01$ctl06','')">6</a>&nbsp;<a href="javascript:__dopostback('dgawards$ctl01$ctl07','')">7</a>&nbsp;<a href="javascript:__dopostback('dgawards$ctl01$ctl08','')">8</a>&nbsp;<a href="javascript:__dopostback('dgawards$ctl01$ctl09','')">9</a>&nbsp;<a href="javascript:__dopostback('dgawards$ctl01$ctl10','')">10</a>&nbsp;<a href="javascript:__dopostback('dgawards$ctl01$ctl11','')">...</a></td>     </tr> 

btw, pagination option appears upon clicking on "search" button in main page.

you cannot iterate through list of pre-defined elements because after make click() page refreshes , elements become stale

you can try below:

from selenium.common.exceptions import nosuchelementexception      page_counter = 2 while true:     try:         if not page_counter % 10 == 1:             driver.find_element_by_link_text(str(page_counter)).click()             page_counter += 1         else:            driver.find_elements_by_link_text("...")[-1].click()             page_counter += 1     except nosuchelementexception :         break 

this should allow switch next page while it's possible


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -