Python, Selenium: "The element is no longer bound to the DOM"

I clean the website, www.lipperleaders.com . I want to get funds from Singapore. I successfully implemented a drop-down list and retrieved the contents of the first page that appeared after sending the parameters. But when I try to go to the next pages (making the code by pressing the next button), I get an error message 'Element is no longer attached to the DOM'.

My code is about 100 lines, but I can give a general idea of ​​the flow of execution of my code:

...                    # creating driver object and all the imports
def main():
    ...
    result = find_elements_by_tag_name('span')  
    ...
    driver.find_element_by_id("ctl00_ContentPlaceHolder1_ucDataPager_btnNext").click()
    main()
main()

This code works fine for the first page, but when main()called again after pressing the next button. Before this recursive method, I also tried to put this inside a loop, and then the same error.

And if I write the same code as:

# some code
result = find_elements_by_tag_name('span')  
driver.find_element_by_id("ctl00_ContentPlaceHolder1_ucDataPager_btnNext").click()
# some code
driver.find_element_by_id("ctl00_ContentPlaceHolder1_ucDataPager_btnNext").click()
.
.

- , , . driver.find_element_by_id().click() 500 , , . , .

, , .

+4
2

, javascript. : implicitly_wait, .

from selenium import webdriver

ff = webdriver.Firefox()
ff.implicitly_wait(10) # seconds
...
myDynamicElement = ff.find_element_by_id("myDynamicElement")

http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#implicit-waits

+5

, , , , - . Which gets loaded every time but you found it earlier, .

, , :

void clickOnStaleElement(String id, WebDriver driver) {
    try {
        driver.find_element_by_id(id).click();
    } catch (StaleElementReferenceException e) {
        // Trying to find element stale element
        clickOnStaleElement(id, driver);
    } catch (NoSuchElementException ele) {
        clickOnStaleElement(id, driver);
    }
 }
+1

Source: https://habr.com/ru/post/1542033/


All Articles