Python Forum
Ajax and Selenium - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Ajax and Selenium (/thread-18720.html)



Ajax and Selenium - ankitjindalbti - May-28-2019

I am trying to automate filling a form on a website. There are two dropdowns like Country and States. Based on the Country selected in first drop down, the values in second drop down are loaded using Ajax.I am able to select Country in first drop down using Selenium Webdriver, but then it is not able to select State from second drop down.. Rather it gives following error :

selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of <select id="ctl00_ContentPlaceHolder1_ReportViewer1_ctl04_ctl05_ddValue" class="aspNetDisabled" name="ctl00$ContentPlaceHolder1$ReportViewer1$ctl04$ctl05$ddValue"> 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


RE: Ajax and Selenium - metulburr - May-28-2019

What is the website so we can tinker with it? And your code so we can just run it.

A couple of things to try in the meantime based on searching....

A StaleElementReferenceException is thrown when the element you were interacting is destroyed and then recreated.
wait.until(ExpectedConditions.stalenessOf(whatever element));
or
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("whatever elemnt")))
Other responses seem to be accessing the problematic element in a loop before throwing the exception


RE: Ajax and Selenium - ankitjindalbti - May-30-2019

I am getting this error now:

AttributeError: 'module' object has no attribute 'stalenessOf'


RE: Ajax and Selenium - ankitjindalbti - May-31-2019

Problem solved now by using fuction staleness_of()