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

My issue relates to “stale element not found

Caused by: org.openqa.selenium.StaleElementReferenceException: stale element reference: stale element not found
At object: ‘Object Repository/PHS/Page_Sign in to your account/btn_clickSignIn’

Here are my details,

I’m not sure that it may relate to duplicate element but in different page then KS thrown stale error.

2023-09-29_13-16-36

Here is my log in page, when running test case. Found no issue on this page. But I found error while in Enter Password page.

2023-09-29_13-18-42

Is this error cause from different button hold same locator (#idSIButton9)? Here is my log viewer.

And here was my error log details ==>

=============== ROOT CAUSE =====================
Caused by: org.openqa.selenium.StaleElementReferenceException: stale element reference: stale element not found
At object: ‘Object Repository/PHS/Page_Sign in to your account/btn_clickSignIn’

For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html

09-29-2023 01:09:34 PM click(findTestObject(“PHS/Page_Sign in to your account/btn_clickSignIn”))

Elapsed time: 0.590s

Unable to click on object ‘Object Repository/PHS/Page_Sign in to your account/btn_clickSignIn’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/PHS/Page_Sign in to your account/btn_clickSignIn’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:74)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:40)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:620)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$2.call(Unknown Source)
at PHS LogIn.run(PHS LogIn:34)
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:448)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1695967759614.run(TempTestCase1695967759614.groovy:25)
Caused by: org.openqa.selenium.StaleElementReferenceException: stale element reference: stale element not found
(Session info: chrome=117.0.5938.132)
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: ‘STRAWBERRY MAC’, ip: ‘192.168.5.115’, os.name: ‘Windows 11’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_362’
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 117.0.5938.132, chrome: {chromedriverVersion: 116.0.5845.96 (1a3918166880…, userDataDir: C:\Users\abc\AppData\L…}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:64141}, 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:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: f4a472f9c718752a0a35ae9f175ebca5
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.click(RemoteWebElement.java:84)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.lambda$new$0(EventFiringWebDriver.java:404)
at com.sun.proxy.$Proxy11.click(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.click(EventFiringWebDriver.java:417)
at org.openqa.selenium.WebElement$click.call(Unknown Source)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.clickUntilSuccessWithTimeout(ClickKeyword.groovy:81)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.clickUntilSuccessWithTimeout(ClickKeyword.groovy)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.doCall(ClickKeyword.groovy:67)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.call(ClickKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:74)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:40)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:620)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$2.call(Unknown Source)
at Script1695959907742.run(Script1695959907742.groovy:34)
… 11 more
)

I couldn’t find out why it thrown Stale Element not found.

Need your expertise to guide me, thank you.

2 Likes

Use below code before Click on SignIn Button
WebUI.waitForElementPresent(findTestObject(‘Page_Sign in to your account/btn_clickSignIn’), 20)

Here are some potential solutions to handle StaleElementReferenceException:
Refresh the web page before accessing the web element.
Use the WaitforElement to locate the element Proper.
Use wait to ensure the element is present or refreshed before interacting with it.
Check reference of object from object repository.

@atul.rai Element that found error was on same page after I enter my username. Why do I need to add that wait for element present again? Please explain.

Can you share the XPath used for the object?
try text
like
//button[text()=‘Next’] for Next Button and
//button[text()=‘Sign in’] for Sign in Button

I think you used the same object for both Next Button and Sign in.
That’s the reason you are getting the Stale Element Exception

@bharathi.a you’re correct, both button use same xpath or css. then how can I make it moving forward?

2 Likes

Don’t use CSS to create objects. use the object I shared in the previous reply. if you use the same object for more than one button or text on the same page then you will get a Stale Element Reference Exception.

Use unique objects for both the Buttons

1 Like

@bharathi.a thanks a lot for your support teaching me, newbie for Katalon Studio. Thanks

1 Like

Always welcome

1 Like

Please don’t make blanket statements like that without explaining why. There is absolutely NOTHING wrong with using CSS selectors to locate elements – that’s how the www works. To my knowledge, no rendering engine uses XPATH (an application of XML) to locate anything, anywhere, ever.

1 Like

+1 from me

2 Likes

Please Explain why ?

since they used the same CSS for both the Next and Sign-in buttons. when we try to use CSS we will always end up creating identical objects for both the buttons.

so it would be wise to go with the only difference between both the buttons is may be the attributes or text without knowing what is present in the DOM. I suggested you go with the only visible difference to both is the text in the Button.

Buttons are mostly created using the //Button Tag
text is mostly inside the same tag

so I suggested to use //button[text()=“Next”] and //button[text()=“SIGN in”]

2 Likes

You’re explaining to me what your method achieves, which is fine, but it’s not what I asked you about.

Disclosure: I always use CSS, I have never used XPath. I have NEVER received a stale element exception. Not even ONCE.

@Russ_Thomas
Then give your solution for the Blocker and explain under what scenario the Stale Element Exception will come.

Switch and bait? That’s novel but still tiresome.

If you don’t reword your post it will stay here misinforming users about a key part of testing technology.

I’m still waiting for your answer.

That’s my answer for the blocker weather you like it or not. There is no need to Reword my answer. if you think you have a better answer then give your answer.

2 Likes

I know. No one is questioning your answer.

I agree. Stop being disingenuous. I’m talking about your blanket statement – a completely different point.

You really are way off base it’s not even funny. THERE IS NOTHING WRONG WITH YOUR SOLUTION.

Sorry for not able to answer, just i read all conversion ,posted and suggested solutions by experianced member and i hope your issue has been resolved.

what to explain?
looks like you are very good with xpath
fine.
and as pointed, the solution provided by you is coorect.
but you know nohing about css.

not sure what @Russ_Thomas replied in the banned post but i will be very curious to see it, an he have a chance to explain in also for mortals.

just saying.

side note, xpath is an abomination.
it is not browser native.
it is for lazy people.

it works.
but it is still an abomination.
i never used and never will.

my two cents.
kindly bann me also.