Selenium throws "Element is no longer valid" after WaitForElement

It's strange here. I am using Selenium WebDriver with IE11 and a C # test file that I am writing.

      driver.Navigate().GoToUrl("testpage.aspx");
      WaitUtility.WaitForElement(By.Id("HEADER_ID"));    //Waits for element to be present
      var element = Driver.FindElement(By.Id("HEADER_ID"));  //fetches the element
      Assert.IsTrue(element.Displayed); //verifies that the element is present

      

Ironically, the above code will successfully execute the WaitForElement command (which should mean the element is present), but the element.Display method will return false.

So Selenium Expects an element to be present. Before continuing to then throw an error saying the error does not exist.

-

Additional information: Sometimes the test program will run without problems. It sometimes returns "the element is already invalid / Stale Element Reference Exception, which I researched here on StackOverflow, but no example applies to my situation, as this exception is usually thrown when a DOM object is recreated with the same attribute definition, but in my case the object has been successfully positioned using the WaitForElement method and I cannot imagine my element being recreated or not DOM bound before the next "element.Displayed" method is called.

Selenium version: x64 Selenium InternetExplorerDriver 2.42.0
OS: Windows 7
Browser: Internet Explorer 11
Browser version: 11.0.9600

      

+3


source to share


1 answer


I don't have enough comments to comment on - and I'm afraid this is not an answer / solution.

But ... I think I ran into a similar case. I wait until the element exists and then try to push and use the same element. If it goes past the wait, it will mean that the item exists, but then no click is made. Nothing else on the page has changed. But I am using remotewebdriver and Python bindings with Chrome and FireFox. Both the remote machine (Ubuntu VM) and my local machine (W7Pro) are 64 bits.

When I was looking for similar examples I found this:

Python Selenium WebDriverWait and click unique by providing StaleElementReferenceException ()



... these are the same symptoms. Python is still in use. But not using a remote driver.

So the problem seems to be the same in all three cases. The settings are all slightly different though.

I haven't found a solution. As far as I can tell, the guy was not in the link above.

So, I'm intrigued to see if you can get there with it!

+1


source







All Articles