Stale element not found, is this relate to using same Object?

@jirayu.s

In a previous post I recommended you to disable Smart Wait.

Now I have changed my opinion.

Smart Wait is the only pragmatic solution for you to pass the sign-in procedure of Azure DevOps.


I found that you are trying to automate the sign-in procedure into Microsoft Azure DevOps. I created my Azure DevOps account, and tried to write a Katalon Test Case that automates signing-in to it. My code is as follows:

import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable

TestObject makeTestObject(String id, String xpathExpression) {
    TestObject tObj = new TestObject(id)
    tObj.addProperty("xpath", ConditionType.EQUALS, xpathExpression)
    return tObj
}

String url = "https://dev.azure.com/${GlobalVariable.ACCOUNT}"
WebUI.openBrowser(url)
WebUI.setViewPortSize(800, 800)

TestObject loginfmt = makeTestObject("loginfmt", "//input[@name='loginfmt']")
WebUI.waitForElementClickable(loginfmt, 20)
WebUI.sendKeys(loginfmt, GlobalVariable.EMAIL)

TestObject nextButton = makeTestObject("Next", "//input[@id='idSIButton9']")
WebUI.waitForElementClickable(nextButton, 20)
WebUI.click(nextButton)

TestObject passwd = makeTestObject("Passwd", "//input[@name='passwd']")
WebUI.waitForElementClickable(passwd, 20)
WebUI.sendKeys(passwd, GlobalVariable.PASSWD)

TestObject signinButton = makeTestObject("SignIn", "//input[@id='idSIButton9']")
WebUI.waitForElementClickable(signinButton, 20)
WebUI.click(signinButton)

TestObject yesButton = makeTestObject("Yes", "//input[@id='idSIButton9']")
WebUI.waitForElementClickable(signinButton, 20)
WebUI.click(signinButton)

WebUI.closeBrowser()

With Smart Wait enabled, this code passed.

With Smart Wait disabled, this code failed with Stale Element Reference Exceptions at several statements.


I looked at the HTML of the Azore DevOps Sign-in page and found that it is heavily JavaScript-driven.

I found that the page is driven by a rich set of JavaScript codes. And your test case script must keep in sync with the JavaScript codes running in the browser.

However, none of WebUI.waitFor*** keywords are capable to synchronize with the JavaScript in browser. Therefore we can not solve the “stale element reference” problem using any of WebUI.*** keywords. I think it is pointless to discuss how to utilize WebUI.waitFor*** and WebUI.delay(n) keywords for this case.

As @Brandon_Hein told at Stale element not found, is this relate to using same Object? - #96 by Brandon_Hein , the Smart Wait talks to the JavaScript running inside browser and moinitor the modifications in the DOM. A Test Case script can get in sync with JavaScript runnging inside browser by enabling Smart Wait.