SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

[Enhancement] Relocating web element on StaleElementReferenceException #5995

Open lukeis opened 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 5995

Hi,

My name is Danail Branekov and I work for SAP AG. My team has implemented a couple
of Selenium tests which represent the integration tests of our web application. The
tests are usually executed successfully locally but used to fail quite frequently on
the build server due to misterious StaleElementReferenceException. I have been searching
quite a lot on the internet about possible causes and the most relevant article I came
up to is http://www.jeromemueller.ch/archives/311/webdriver-staleelementreferenceexception

I implemented Jerome's proposal to create a wrapper of Selenium web elements and would
like to share it (see the attachment). In case you find it useful, please feel free
to include it in Selenium.

The wrapper implementation I propose uses a InvocationHandler to dispatch WebElement
methods invocations. The handler would try to delegate method invocations and in case
the delegate is stale, it would rellocate it. The implementation works for WebElements
found using WebDriver, and WebElement found by webElement.findElement(By) or webElement.findElements(By)
In order to create a web element wrapper one needs to instantiate FailSafeWebElement,
for example

WebElement newElement = new FailSafeWebElement(driver, By.className("someCssClass"));

After the FailSafeWebElement is instantiated, it can be used just like any other web
element. In case the element matcher (By) cannot find such an element, invoking any
of the methods would throw NoSuchElementException. In addition, FailSafeWebElement
offers a service method waitElementDisplayed which would wait until the element is
visible.

Cheers, Danail

Reported by danailster on 2013-07-25 15:41:30


lukeis commented 8 years ago

Reported by barancev on 2013-07-30 01:12:05

lukeis commented 8 years ago
Hi,

This "StaleElementException" issue is one which disturbs my work often and i have to
always use Thread.sleep to overcome it.

Please implement the proposal of Danail on priority basis.

Thanks,
Sreevatsa

Reported by sreevatsa.raju on 2013-10-29 09:38:50

lukeis commented 8 years ago
This or equivalent mechanism would be really valuable, if introduced. I am also suffering
with the same stuff.

Reported by ESimeonov on 2013-10-29 11:41:48

lukeis commented 8 years ago

Reported by barancev on 2013-10-29 14:40:51

lukeis commented 8 years ago
Here is a JUnit test for the proposed implementation

Reported by danailster on 2013-11-07 00:45:45


lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 17:45:54