StaleElementReferenceException while trying to find element in selenium using node js

201 views
Skip to first unread message

Latha Reddy

unread,
May 8, 2019, 10:05:38 AM5/8/19
to Selenium Users
As part of my project , I am working on two different different frameworks , one is built on Selenium - Java , another is on Selenium - Node js. I could see selenium functions behaving differently in both frameworks for few elements , in the same script and on same website application. The different behaviour's observed are:

1. The same script , is giving StaleElementReferenceException while trying to findElement in Selenium - node JS even after increasing wait from 2 secs to 30 secs, where as I am able to find the same element in Selenium - java solution with just implicit wait itself of 20secs. 
Fix : The fix i did for above issue is to refresh the page and then find element - then its working well in selenium - node js too

2. This is happening only for particular element : selenium - node js solution, the element is able to be found out, able to get its text , but not clickable. 
     Where as the same script working well in selenium - java solution , the element found out, able to read its text, and clickable too.

I basically need info on why selenium javascript libraries behaving differently in some cases , where as selenium -java libraries working well in those cases as well.

Your help is much appreciated. 

Joe Ward

unread,
May 8, 2019, 10:09:30 AM5/8/19
to seleniu...@googlegroups.com
Because Java != JavaScript? The implementation is different. As presumably your code will be.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b39aa8e7-d77f-4377-9305-e485f20848d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Krishnan Mahadevan

unread,
May 8, 2019, 10:13:27 AM5/8/19
to seleniu...@googlegroups.com

Joe,

 

Irrespective of whether one uses Java (or) JavaScript, I believe its going to be the server component that would be responsible for doing the actual interactions with the web browser right ?

So for IE it would be InternetExplorerDriver (or) EdgeDriver, for Chrome it would be ChromeDriver and for Firefox it would be geckodriver.

 

AFAIK, the client bindings (Java or Javascript Selenium APIs) are just a way to form the W3C spec compliant payload, set the required headers and trigger the appropriate HTTP Call [ GET/POST/PUT/DELETE] against the predefined http end-points.

 

So just curious to know, how would the difference in client bindings play a role here?

 

Note: I am conveniently neglecting any javascript injections being done by the test code via driver.executeScript()

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.com/

Joe Ward

unread,
May 8, 2019, 10:20:15 AM5/8/19
to seleniu...@googlegroups.com
Fair cop.

Any differences you're likely to find are more probably going to be down to individual implementation.

Latha Reddy

unread,
May 8, 2019, 12:18:08 PM5/8/19
to seleniu...@googlegroups.com
Agree that implementation is different. In my entire suite having 58 test cases, i am facing issue only with two elements using node js framework.

why i am confident that it is not issue with element state is, it is working well using java solution.

Joe Ward

unread,
May 8, 2019, 1:21:28 PM5/8/19
to seleniu...@googlegroups.com
Please provide code samples for both implementations so we can see what you're referring to.

Latha Reddy

unread,
May 9, 2019, 3:01:12 PM5/9/19
to Selenium Users
Ok,

For 1:
Using node Js - which is giving stale element exception
-------------------------------------------------------------------------------
 import { By } from 'selenium-webdriver'
 let el = await driver.wait(until.elementLocated(By.xpath(myxpath)), 30000) // though timeout increased , getting staleelement

Using Java - which is working well
-----------------------------------------------------
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS)
WebElement el = driver.findElement(By.xpath(myxpath))

For 2:
Using node Js - which is not able to click element
-------------------------------------------------------------------------------
 import { By } from 'selenium-webdriver'
 let el = await driver.wait(until.elementLocated(By.xpath(myxpath)), 30000)
await driver.wait(until.elementIsVisible(el), 10000) //Increasing the time is not solving here
await driver.click(el) // click action is not happening some times, sometimes able to click it seems because the color of button changes but no action performs

Using Java - which is working well
-----------------------------------------------------
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS)
WebElement el = driver.findElement(By.xpath(myxpath))
el.click() 


On Wednesday, May 8, 2019 at 10:51:28 PM UTC+5:30, Joe Ward wrote:
Please provide code samples for both implementations so we can see what you're referring to.

On Wed, 8 May 2019 at 17:17, Latha Reddy <latha....@gmail.com> wrote:
Agree that implementation is different. In my entire suite having 58 test cases, i am facing issue only with two elements using node js framework.

why i am confident that it is not issue with element state is, it is working well using java solution.

On Wed, 8 May 2019, 7:39 pm Joe Ward, <ddl...@gmail.com> wrote:
Because Java != JavaScript? The implementation is different. As presumably your code will be.

On Wed, 8 May 2019 at 15:05, Latha Reddy <latha....@gmail.com> wrote:
As part of my project , I am working on two different different frameworks , one is built on Selenium - Java , another is on Selenium - Node js. I could see selenium functions behaving differently in both frameworks for few elements , in the same script and on same website application. The different behaviour's observed are:

1. The same script , is giving StaleElementReferenceException while trying to findElement in Selenium - node JS even after increasing wait from 2 secs to 30 secs, where as I am able to find the same element in Selenium - java solution with just implicit wait itself of 20secs. 
Fix : The fix i did for above issue is to refresh the page and then find element - then its working well in selenium - node js too

2. This is happening only for particular element : selenium - node js solution, the element is able to be found out, able to get its text , but not clickable. 
     Where as the same script working well in selenium - java solution , the element found out, able to read its text, and clickable too.

I basically need info on why selenium javascript libraries behaving differently in some cases , where as selenium -java libraries working well in those cases as well.

Your help is much appreciated. 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seleniu...@googlegroups.com.

Krishnan Mahadevan

unread,
May 10, 2019, 12:19:38 AM5/10/19
to seleniu...@googlegroups.com

Latha,

What happens when you get rid of the implicitWaits in your Java code and instead resort to explicit waits (via WebDriverWait) like how you have done in your nodeJS code?

 

I think you are comparing apples and oranges here.

Implicit Waits and explicit Waits aren’t the same.

 

Your NodeJS code is using Explicit Waits whereas your Java code is using Implicit Waits. You might want to try make them both use Explicit Waits and then see what happens.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.com/

 

From: <seleniu...@googlegroups.com> on behalf of Latha Reddy <latha....@gmail.com>
Reply-To: <seleniu...@googlegroups.com>
Date: Friday, May 10, 2019 at 12:32 AM
To: Selenium Users <seleniu...@googlegroups.com>
Subject: Re: [selenium-users] StaleElementReferenceException while trying to find element in selenium using node js

 

Ok,

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.


To post to this group, send email to seleniu...@googlegroups.com.

Latha Reddy

unread,
May 10, 2019, 8:33:03 AM5/10/19
to Selenium Users
await driver.manage().timeouts().implicitlyWait(30000)
is already defined in project level in node js project as well. Only finding element is getting through explicitwait , to avoid sync issue in case of.

Shawn McCarthy

unread,
May 10, 2019, 8:41:12 AM5/10/19
to Selenium Users
I don't believe you are suppose to mix implicit and explicit waits.

Venu Adhi

unread,
May 10, 2019, 8:48:45 AM5/10/19
to Selenium Users
Well I am not sure about implicit/explicit wait in  Node JS, Googling got some information that both wait having issues around,


On Friday, May 10, 2019 at 9:49:38 AM UTC+5:30, Krishnan Mahadevan wrote:

Krishnan Mahadevan

unread,
May 10, 2019, 9:00:29 AM5/10/19
to seleniu...@googlegroups.com
Agree with Shawn. Not a good idea to mix implicit and explicit waits because their behavior is not determined.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Latha Reddy

unread,
May 10, 2019, 9:13:17 AM5/10/19
to Selenium Users
so, what is way to get rid of stale element exceptions of particular case of elements , and implicitwait needs to be declared in project level, which will work well for 99% of elements

Amr Kamel

unread,
Jun 10, 2019, 3:31:10 PM6/10/19
to Selenium Users
any solution yet im encountering same issue 

raja nadar

unread,
Jun 10, 2019, 11:53:43 PM6/10/19
to seleniu...@googlegroups.com
Hi all, 

Staleelement exception occurs when the particular element is not attached to DOM. So you can put a explicit wait to wait until the element is enabled. Suppose even after that element is not available then you should refresh the page. 



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages