Monday, May 16, 2011

StaleElementReferenceException while running Selenium2 WebDriver

For the last one day i have started working on WebDriver and the first issue that came for me was the StaleElementReferenceException . My example was simple , ie do a google search for a word and click on submit .

First time , it worked ..Added some more commands i started getting this exception org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM

Reasons for this issue was due to the faster load of the page .Kept a Tread.sleep command and it worked .

As thread.sleep is not a good way of programming , i used

WebDriverWait wait = new WebDriverWait(driver, 10);


When i searched a bit more , found one more way to make it wait ,

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS)


called impilicit way of waiting which also worked...

WebdriverWrapper and WebElementWrapper can also be used which will get the new WebElement Object .

No comments:

Post a Comment