简体   繁体   中英

How to use Selenium function back() and I loss my variable in Python?

I'm new to Python.

I met a BIG problem in Python!!

I visit a website and put about 200 options from a dropdownlist in a array.

I want to click every options in the array and click javascript button to submit.

Take something I want from that page and back to previous page click another option.

Do those actions about 200 times in a for loop.

Here is the code:

for option in arrName:
    if count > 0:
        option.click()
        string = u'Something'
        link2 = browser.find_element_by_link_text(string.encode('utf8'))
        link2.click()
        //"do something I want"
        browser.back()
    count = count +1

In this code, I don't want to use first option.

PROBLEM comes,after the program click the second option, click the link2, and browser.back() , it answer me:

` StaleElementReferenceException: Message: stale element reference: element 
is not attached to the page document

that means the options in array disappear?

How should I use the options in the array when the browser.back() in for loop?

Thanks

Yes, this is happening because of DOM refresh. You cannot simply iterate over an array and click back and forth. Best option is to find the element in runtime and then click. Avoid option.click() instead, find the next element with find_element . If you are not sure how to accomplish that then please provide the html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM