Reputation: 1432
Here's a strange one. I'm using Selenium WebDriver with IE11 and a C# testcase I'm 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
Weirdly enough, the above code will successfully run the WaitForElement command (which should mean that the element is present) but the element.Display method will return false.
So Selenium Waits for an element to be present Before continuing only to then throw an error saying that the error doesn't exist.
--
Extra info: Sometimes the testcase will execute without a problem. Sometimes, it'll return "element no longer valid / Stale Element Reference Exception which I've researched here on StackOverflow but no example seems to apply to my situation as this exception is usually thrown when a DOM object has been recreated with the same defining attributes, but in my case, the object is successfully located with the WaitForElement-method and I can't imagine that my element has been recreated or unattached to the DOM before the next method "element.Displayed" is called.
Selenium version: x64 Selenium InternetExplorerDriver 2.42.0
OS: Windows 7
Browser: Internet Explorer 11
Browser version: 11.0.9600
Upvotes: 3
Views: 3049
Reputation: 69
Having success with Actions interactions to get around this problem: using OpenQA.Selenium.Interactions;
Actions action = new Actions(driver); action.MoveToElement(xrmBrowser.Driver.FindElement(By.XPath("//span[contains(text(),'Contacts')]"))).Click().Build().Perform();
Upvotes: 0
Reputation: 258
I don't have enough rep to comment - and I'm afraid this isn't an answer/solution.
But ... I think I have run into a similar thing. I wait until an element exists, and then try and click on/use the same element. If it gets past the wait, that would imply that element is there, but then the click fails. Nothing else on the page has changed. But I'm using the remotewebdriver and Python bindings with Chrome and FireFox. Both the remote machine (a Ubuntu VM) and my local machine (W7Pro) are 64 bit.
When I searched for similar examples, I found this:
Python Selenium WebDriverWait and Click inconsistently giving StaleElementReferenceException()
... which is the same symptoms. Still using Python. But not using the remote driver.
So the problem seems to be the same in all three instances. Although the setups are all slightly different.
I never did find a solution. Neither did the guy in the link above as far as I can tell.
So I'm intrigued to see if you get anywhere with it!
Upvotes: 1