Selenium error in Python3, element reference is stale; no longer attached to DOM, not in the context

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Selenium error in Python3, element reference is stale; no longer attached to DOM, not in the context

Saif Ayan Khan
OS:  
OSX High Sierra
Selenium Version:  
3.12.0, Selenium Web Driver
Browser:  
Firefox

I am trying to web scrap http://compbio.charite.de/phenomizer/

After giving a search value, and pressing enter/return, I am getting a list of predictions, from which either I need to either double click on any of them or right click and select the fourth option from the context menu.

I am doing this for multiple searches, by passing the words in a list and entering each list item in the search box. The error is not coming for the first search result, but from the second.

The list that I have to select from I am giving as an output with indices from where the user can select, the code that does the selection is as follows - 

    for entry in inputs:
    
        inputElement = driver.find_element_by_id('ext-gen86')
        inputElement.clear()
    
        time.sleep(1)
        inputElement.send_keys(entry)
    
        time.sleep(1)
    
        inputElement.send_keys(Keys.RETURN)

        time.sleep(1)
    
        options = driver.find_element_by_class_name('x-grid3-scroller')
        optionText = options.text.split('\n')
    
        dictDis = {}
        for i,j in enumerate(optionText[1::2]):
            print (i+1, '-', j)
            dictDis[i+1] = j
        
        selection = input("Enter the indices you want to incorporate as patient's features separated by a space - \n").split(' ')
        
        for index in selection :
            text = '//*[contains(text(), "' + dictDis[int(index)] + '")]'
            time.sleep(2)
            toclick = driver.find_element_by_xpath(text)
            time.sleep(2)
            while True:
                if (toclick == driver.find_element_by_xpath(text)):
                    action.double_click(toclick).perform()
                    break
                else:
                    toclick = driver.find_element_by_xpath(text)
                    

The above if else was just an experiment to see if it works.
I have even tried it in an infinite try except loop like

    while True:
        try:
            action.double_click(toclick[index]).perform()
            break
        except:
            continue

Also I have tried giving explicit and implicit waits, but of no avail.

The same error pops up whether I use multiple different classes, or any other identification, tried path with searching for text, etc for the item to be selected; but everyone threw the same error. In the code above I am double clicking on it, but also right clicking and selecting option doesn't work.

The error is - 

    The element reference of <div id="ext-gen620" class="x-grid3-row x-grid3-row-selected "> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed


P.S. - I have tried every possible solution given in a google search result upto 5 pages and also while typing the question title, I went through all the predictions that StackOverflow gave as might have my answer. In short all they say is wait for it. I did, nothing happens.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9858efee-7742-47ad-a6e4-7516b5d4125f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.