I have a test case that reports a failure when it should not be and I’m not finding why. The test is simple, I have an input screen with multiple panels that are the same. Each panel has inputs and a button to clear the inputs that I am testing.
My test walk through:
- I am setting the text to each input
- I click on the ‘clear’ button to show the confirmation dialog
- I click on the confirmation ‘OK’ button to
- JS runs to clear the inputs
- I am testing that the inputs have a blank value
This test falsely fails about 90% of the time. Sometimes it works, but most of the time it fails. The screen being tested never changes, the inputs are always there and the inputs are clear after the JS runs to clear them. The error when it fails is always “stale element reference: element is not attached to the page document”. The error does not always occur on the same waitForElementAttributeValue line. The error randomly fails on either the 8th, 9th or 10th waitForElementAttributeValue line:
WebUI.waitForElementAttributeValue(findTestObject("input/input08", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input09", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input10", ["idx":1]), "value", "", 2)
What would cause this error?
My test case:
WebUI.navigateToUrl(GlobalVariable.baseurl + ‘/input/’ + GlobalVariable.editid + ‘/edit#!/packages’)
WebUI.verifyElementAttributeValue(findTestObject(‘common/meta_application’), ‘data-screenid’, ‘input.packages’, 20)
WebUI.waitForElementNotVisible(findTestObject(“common/spinner”), 20)
WebUI.setText(findTestObject("input/input01", ["idx":1]), "input01")
WebUI.setText(findTestObject("input/input02", ["idx":1]), "input02")
WebUI.setText(findTestObject("input/input03", ["idx":1]), "input03")
WebUI.setText(findTestObject("input/input04", ["idx":1]), "input04")
WebUI.setText(findTestObject("input/input05", ["idx":1]), "input05")
WebUI.setText(findTestObject("input/input06", ["idx":1]), "input06")
WebUI.setText(findTestObject("input/input07", ["idx":1]), "input07")
WebUI.setText(findTestObject("input/input08", ["idx":1]), "input08")
WebUI.setText(findTestObject("input/input09", ["idx":1]), "input09")
WebUI.setText(findTestObject("input/input10", ["idx":1]), "3210")
WebUI.setText(findTestObject("input/input11", ["idx":1]), "1,111.11")
WebUI.setText(findTestObject("input/input12", ["idx":1]), "2,222.22")
WebUI.setText(findTestObject("input/input13", ["idx":1]), "3,333.33")
WebUI.click(findTestObject("input/clearbtn", ["idx":1]))
WebUI.waitForElementVisible(findTestObject("common/confirmationdialog"), 2)
WebUI.click(findTestObject("common/confirmationdialogok"))
WebUI.waitForElementAttributeValue(findTestObject("input/input01", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input02", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input03", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input04", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input05", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input06", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input07", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input08", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input09", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input10", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input11", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input12", ["idx":1]), "value", "", 2)
WebUI.waitForElementAttributeValue(findTestObject("input/input13", ["idx":1]), "value", "", 2)
Object Example: (only ng-model changes for each)
Selection Method: Attributes
Object’s Properties: xpath = //div[@name=“packages”]/div[${idx}]//input[@ng-model=“input05”]
Detect Object: checked
Error:
Stack trace: com.kms.katalon.core.exception.StepFailedException:
Unable to verify if object ‘Object Repository/input/input08’ has attribute ‘value’ with value ‘’
Root cause: org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
Session info: chrome=70.0.3538.110
Driver info: chromedriver=2.43.600210