Hello friends,
i get a “StaleElementReferenceException” in several TestCases that are running on our Jenkins / Linux Environment in Firefox headless mode.
I’m trying to figure out what I can do since days but I still have no solution for this issue.
I found already some Topics over here, like:
@Brandon_Hein wrote the following to avoid these exception:
1.) Ensure that EVERY element reference is 1-time use . In other words, locate the element, use it, and DO NOT use that same reference again. If you want to reference that element again, you should re-locate it in the HTML every single time.
2.) Ensure that you have proper wait conditions in place for every action you take in your application. Always wait for the page to be “static” prior to locating elements and using them.
I think I have already implemented my test case according to these guidelines.
So here is my error log:
Here the rest that didn’t fit in the first screenshot:
As you can see in the first screenshot, there are 3 (sub-) steps that are passed, before the step failed, where it tries to click the element.
This comes from my own click-Method I wrote:
class TestUtilities {
static void click(TestObject testObject) {
WebUI.scrollToElement(testObject, GlobalVariable.timeout)
WebUI.waitForElementClickable(testObject, GlobalVariable.timeout)
WebUI.waitForElementPresent(testObject, GlobalVariable.timeout)
WebUI.click(testObject)
}
static TestObject button(String buttonText) {
TestObject testObject = new TestObject()
testObject.addProperty("tag", ConditionType.EQUALS, "button")
//testObject.addProperty("type", ConditionType.EQUALS, "button")
testObject.addProperty("text", ConditionType.EQUALS, buttonText)
return testObject
}
static TestObject tab(String tabName) {
TestObject testObject = new TestObject()
String xpath = new String()
xpath = "//div[starts-with(@id, 'mat-tab-label-')]"
testObject.addProperty("text", ConditionType.EQUALS, tabName)
testObject.addProperty("xpath", ConditionType.EQUALS, xpath)
return testObject
}
}
In the second method “button” you can see how I create button-Objects and or tab-Objects (third method).
So the test step looks like this:
TestUtilities.click(TestUtilities.button('Submit'))
or
TestUtilities.click(TestUtilities.tab('Person'))
These steps always pass in GUI-mode on my local machine. And also passes in about 99/100 cases in headless mode. But at some points it crashes into this StaleElement exception.
And I have no more Idea what I can do.
As you can see I use already several “waitFor”-commands.
I also set up the xpath for my tab-Element containg the “starts-with”-function because the id is newly generated at every session and looks like mat-tab-label-2, mat-tab-label-5, mat-tab-label-1 or whatever… so the number at the end is not always the same.
In the html-test-report I get via Mail, there is also a screenshot attached right under the Exception-log.
There I can see that the Tab or Button is actually visible at this point.
Any Idea on what I can do?
Thanks a lot and have a nice day!
Simon