Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97762

Continue the script from the same point where the error was thrown

$
0
0

Hello Friends what i want to accomplish is that i want to traverse through pages by clicking the next button but however when i get any error the script stops and i need to rerun the script from where it had stopped basically it should continue fromt the next page after the page it stopped.. follwing codetraverses and also stores the current page number can you help me to proceed further.

def next():
    browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    button = browser.find_element_by_xpath('//*[@id="search"]/div[1]/div[2]/div/span[8]/div/span/div/div/ul/li[9]/a')
    browser.implicitly_wait(10)
    ActionChains(browser).move_to_element(button).click(button).perform()



for i in range(1,399):
        CurentPage_num = browser.find_elements_by_xpath('//*[@id="search"]/div[1]/div[2]/div/span[8]/div/span/div/div/ul/li[@class="a-selected"]')
        for ij in CurentPage_num:
            jq = ij.find_element_by_tag_name('a').text
            print(jq)
        next()

The above code is for the url : https://www.amazon.com/s?i=toys-and-games-intl-ship&bbn=16225015011&rh=n%3A16225015011%2Cn%3A166092011&qid=1578647211&ref=sr_pg_1


Viewing all articles
Browse latest Browse all 97762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>