I am getting the “Stale Element Reference” seemingly at random. I have a page where I capture the text on a vehicle make link and store it to a variable. I then click the link which updates the panel with a new report (not reloading the page). One the new report loads, I then capture vehicle makes from all of the rows in the grid and loop through them to verify that all are the same. Then I click on the 1st rows, model link and do the same process of checking.
This is one point (clicking the model link) that I am randomly getting the error. If it passes this point, it then clicks a bread crumb that takes me back to the original report where I click the Make link, but this time it captures the text and clicks the link for the Model. This seems to be the point that throws this error the most. Again, it seems random as to whether it will pass or get the Stale Element Reference.
Here is a snipping of code where it is doing the checks:
CustomKeywords.'dwKeywords.WaitForSpinner.spinnerNotVisible'('#panel3 multi-comp div div datatable progress-bar div') CustomKeywords.'dwKeywords.MakeModelCheck.verifyMakeModel'(reportName, 'Make') CustomKeywords.'dwKeywords.WaitForSpinner.spinnerNotVisible'('#panel3 multi-comp div div datatable progress-bar div') CustomKeywords.'dwKeywords.MakeModelCheck.verifyMakeModel'(reportName, 'Model') // New Inventory Details Breadcrumb WebUI.executeJavaScript('document.querySelectorAll(\'#panel3 a\')[1].click()', null) CustomKeywords.'dwKeywords.WaitForSpinner.spinnerNotVisible'('#panel3 multi-comp div div datatable progress-bar div') CustomKeywords.'dwKeywords.MakeModelCheck.verifyMakeModel'(reportName, 'Model')
Here is where the CustomKeyword is defined:
public class WaitForSpinner { @Keyword def spinnerNotVisible(String selector) { def count = 0 def spinnerHidden = false if (count >= 20) { return } else { if (spinnerHidden == false) { def classList = WebUI.executeJavaScript('return document.querySelectorAll(\'' + selector + '\')[0].classList', null) if (classList.contains('ng-hide')) { spinnerHidden = true return spinnerHidden } else { count++ WebUI.delay(0.5) spinnerNotVisible(selector) } } } } }
And here is the Error Log from the Katalon Console:
=============== ROOT CAUSE =====================
For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html
07-01-2021 09:18:43 AM Test Cases/VariableOperations/NewCarSalesReports
Elapsed time: 1m - 11.664s
Test Cases/VariableOperations/NewCarSalesReports FAILED.
Reason:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: chrome=91.0.4472.124)
For documentation on this error, please visit: /documentation/webdriver/troubleshooting/errors/
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘DWDEVWS008’, ip: ‘172.16.1.220’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 91.0.4472.124, chrome: {chromedriverVersion: 90.0.4430.24 (4c6d850f087da…, userDataDir: C:\Users\DEVIN~1.BRO\AppDat…}, goog:chromeOptions: {debuggerAddress: localhost:51745}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 2d0245a6651b3aa85bb2510110a68abe
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:19)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.getText(RemoteWebElement.java:166)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.lambda$new$0(EventFiringWebDriver.java:404)
at com.sun.proxy.$Proxy11.getText(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.getText(EventFiringWebDriver.java:463)
at dwKeywords.MakeModelCheck.verifyMakeModel(MakeModelCheck.groovy:80)
at dwKeywords.MakeModelCheck.invokeMethod(MakeModelCheck.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
at NewCarSalesReports.processReports(NewCarSalesReports:126)
at Script1623172074810$processReports.callCurrent(Unknown Source)
at NewCarSalesReports.run(NewCarSalesReports:57)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:369)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:360)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:339)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:331)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:248)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1625145519841.run(TempTestCase1625145519841.groovy:25)
Any help would be greatly appreciated!