Webdriver StaleElementReferenceException
January 26, 2012
1 - When we didn’t wait (or for the wrong thing)
public void clickMakeSomeAttendeesOptional() {makeSomeAttendeesOptionalLink.click();}public void makeOptional(String name) {driver.findElement(String.format(REQUIRED_ATTENDEE_ICON, name)).click(); // StaleElementReferenceException here}
public void clickMakeSomeAttendeesOptional() {makeSomeAttendeesOptionalLink.click();waitUntilVisible(optionalAttendeesLegend);}
2 - Waiting fails
WebDriverWait wait = new WebDriverWait(driver, timeout);wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(String.format(ATTENDEE, names.get(0)))); // StaleElementReferenceException here
// In concrete Page objectpublic void waitUntilMonthViewIsDisplayed() {waitUntilVisible(By.id("mvEventContainer"));}// In abstract parentprotected RenderedWebElement waitUntilVisible(By locator) {WebDriverWait wait = new WebDriverWait(driver, 20);return (RenderedWebElement) wait.until(refreshed(ExpectedConditions.visibilityOfElementLocated(locator)));}private <T> ExpectedCondition<T> refreshed(final Function<WebDriver, T> originalFunction) {return new ExpectedCondition<T>() {@Overridepublic T apply(WebDriver webdriver) {try {return originalFunction.apply(webdriver);} catch (StaleElementReferenceException sere) {throw new NoSuchElementException("Element stale.", sere);}}};}
3 - @FindBy injected elements
@FindBy(id = "tgCol0")private RenderedWebElement gridFirstColumn;
public EventBubble clickGridFirstColumn() {gridFirstColumn.click(); // StaleElementReferenceException herereturn newEventBubble();}
@Overridepublic void click() {try {underlyingElement.click();} catch (StaleElementReferenceException sere) {againLocate();click();}}
protected void againLocate() {underlyingElement = locator.locate();}
4 - findElement on WebElement
WebElement element = driver.findElement(...);WebElement e2 = element.findElement(...);e2.click(); // StaleElementReferenceException here
protected OurWebElement(WebElement underlyingElement, Locator locator) {this.underlyingElement = underlyingElement;this.locator = locator;}
@Overridepublic WebElement findElement(By by) {try {return wrap(underlyingElement.findElement(by),new FindElementLocator(this, by));} catch (StaleElementReferenceException sere) {againLocate();return findElement(by);}}
protected void againLocate() {underlyingElement = locator.locate();}
5 - Bad luck
driver.findElement(By.xpath("//div[text()='" + text + "']")).click(); // StaleElementReferenceException here
// In Concrete PageObject classpublic void toggleCalendar(String name) {findElement( "//div[@class='t23']//div[text()='" + name + "']").click();}// In Abstract parent classprotected WebElement findElement(By by) {return OurWebElement.wrap(driver.findElement(by), new OurWebElement.FindElementLocator(driver, by));}
Conclusion
Posted by master, 0 Comments
Book review: The Mythical Man-Month (by Frederick P. Brooks)
January 8, 2011
The book is 35 years old and it shows in many places. What is fascinating in the book is not so much the solutions that they came up with at that time (obviously some technology hasn’t been around at that time), but that many of the problems they faced are still problems today.
For example in the chapter “Why did the tower of Babel fail?” he writes:
“So it is today. Schedule disaster, functional misfits, and system bugs all arise because the left hand doesn’t know what the right hand is doing. As work proceeds, the several teams slowly change the functions, sizes, and speed of their own programs, and they explicitly or implicitly change their assumptions about the inputs available and the uses to be made of outputs.”
His suggestion to using the telephone often, regular project meetings and a (physical) workbook (that needs to updated by each engineer) are outdated of course. However it is interesting to see, that he pointed his finger on a big problem that is still valid today. We’re still looking to solve that. In the meantime, a lot of things have addressed these concerns: Javadoc, Wikis, Design by contract, Unit tests etc.
So if you decide to read this book and expect to get solutions out of it, you will probably be disappointed. But you will be amazed, that many of the big problems from back then are actually still big problems today. Even more, they seem to be problems that still catch projects by surprise as they rediscover them. In that regard, the time spent reading this small book is time very well spent!
Posted by Jerome Mueller, 0 Comments
Swiss Softball National Team Training
January 18, 2010
I used these kinds of pictures for the Trainingsday of the Swiss National Softball Team to explain some common mistakes. All the pictures here [pdf], in case somebody wants to have a closer look at them later on.
Posted by master, 0 Comments
Some Christmas Cards
December 24, 2009
Merry Christmas to everybody.
Posted by Jerome Mueller, 0 Comments
Sweet child of mine - violin
October 5, 2009
Sometimes, one word is enough: Wow!!!
Posted by Jerome Mueller, 2 Comments
Meteor come - BOOM
September 9, 2009
No more defects. No more test phase. No more testers.
Posted by master, 0 Comments
And why did you become extinct?
September 4, 2009
Posted by master, 0 Comments
First Swiss Testing Night - Impressions
June 12, 2009
Here are some impressions from the first Swiss Testing Night:
The Swiss Testing Night Programme. Three quarters of an hour to torment QA people with ideas about Testing by a developer.
I think this was the moment I was the most nervous: Being introduced by Adrian Zwingli (Chief Organizer). Everybody is ready, waiting for you. Then you realize: There’s no way back - only one way to go. That’s when most of the nervousness goes away - kind of like in baseball when you take the mound.
Setting things up. The remote control didn’t work, probably because the infrared receiver was blocked by the podium. And no headset style microphone - the room was set up for a speaker talking from behind the podium. No chance I was going to do that though. So I turned the podium sideways and picked the micro up - Rockstar style
I think that’s the moment I realized that saying “one of the reason for the existence of bugs are bug tracking tools” might not sit too well with our sponsor HP - who sells Quality Center and Winrunner among other things.
Oh well - sometimes you step on somebodys toe - life goes on. That plus HP has a mighty big toe.
This is one of my favorite slides (introducing the second part of the speech). A reference to Starship Troopers (how could you leave out a reference to the best movie ever, if your topic is “Crusade against Bugs”)?
A misunderstanding between the organizers and the location provided for about 20 chairs - the other 80 people had to stand the whole time. Before the speech I thought about having people rotate after every part of the speech. That way most people would get at least 15 min of sitting time. I’m afraid I forgot. Not that it was a good idea to begin with.
All the photos here were taken by Stephan Wiesner (@Stephan: If you’re reading - thanks a lot for letting me use them on my site).














