How To Handle Stale Element Exception - Selenium WebDriver Tutorial

  Рет қаралды 32,365

Let's Kode It

Let's Kode It

Күн бұрын

We will learn how to fix Stale Element Exception in Selenium WebDriver with Java.
It is one of the most tricky to understand and easy to fix and it makes it a popular interview question. You will definitely see this kind of exception while automating a web application.
In this video we will see the reasons for this exception and how we can resolve it.
Rohini's Channel: YumWithRohini
/ @yumwithrohini
Mumbai Masala Toast Sandwich: • Mumbai Masala Toast Sa...
Instagram: / aniltomar
Rohini's Instagram: / its_rohini_tomar
Facebook Page: / its.rohini.tomar
****************************************************************
Complete Test Automation Bundle ($29.99 Only):
Includes 9 Courses, future new test and automation courses will be added to this bundle
courses.letskodeit.com/course...
****************************************************************
Selenium WebDriver With Java ($8.99 Only):
courses.letskodeit.com/course...
****************************************************************
Selenium WebDriver With Python ($8.99 Only):
courses.letskodeit.com/course...
****************************************************************
Selenium WebDriver Bundle ($19 Only):
learn.letskodeit.com/p/seleni...
****************************************************************
Please be our Patron and support us to provide you great content:
/ letskodeit
Website:
www.letskodeit.com
Join Private Facebook Group:
/ letskodeit
Follow us on Facebook and Twitter for technology updates:
/ letskodeit
/ letskodeit

Пікірлер: 73
@uatul25
@uatul25 2 жыл бұрын
Bhai sahab ne 5 min me sikha diya !!! Very well explained .... Thankyou so much sir!!!!!
@LetsKodeItOfficial
@LetsKodeItOfficial 2 жыл бұрын
Hahaha 🙂🙂 Glad you found it helpful :) Please like and share the video and help us spread the word.
@ifelse2542
@ifelse2542 4 жыл бұрын
This is nice, short and easy example to understand that exception. Really nice work.
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
Glad you found it helpful :) Please like and share the video and help us spread the word.
@kiwihour333
@kiwihour333 4 жыл бұрын
Even though i am using Python this has given me an amazing example of a possible fix. I have been trying to fix for days
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
Glad it helped you :) If you like our videos, you can explore our Complete Test Automation bundle here: learn.letskodeit.com/p/test-automation-bundle/?product_id=1483892&coupon_code=KZfaqRS29
@mmat_24
@mmat_24 5 жыл бұрын
easily the best explanation of stale exception I've found, thank you!
@LetsKodeItOfficial
@LetsKodeItOfficial 5 жыл бұрын
Glad you found it helpful :) Please like and share the video and help us spread the word.
@mehdihachimi9624
@mehdihachimi9624 5 жыл бұрын
@@LetsKodeItOfficial ... Same man thank you very much, got what I needed in 71 secs :) much better than the hour I spent in stack
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
@@mehdihachimi9624 Glad you found it helpful, please like and share the video to spread the word and help us. If you like our content, you can enroll in the complete course also here: learn.letskodeit.com/p/selenium-webdriver-with-java/?product_id=342636&coupon_code=KZfaqSELJAVA9
@madhuslifestyle4538
@madhuslifestyle4538 4 жыл бұрын
Wooowwwww.....Very simple....very clear explanation.....
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
Glad you found it helpful, please like and share the video to spread the word and help us :)
@KatRollo
@KatRollo 4 жыл бұрын
This is an on-the-right-path video on the topic. Not suggesting hacky workarounds like try-catch.
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
Glad it helped you :) Please help spread the word by liking and sharing the video.
@irtifakhan17
@irtifakhan17 5 жыл бұрын
you are doing great. No one is so helpful. Please continue to upload videos
@LetsKodeItOfficial
@LetsKodeItOfficial 5 жыл бұрын
Glad you liked this video :) Please like and share the video with your friends.
@satyadeb9932
@satyadeb9932 6 жыл бұрын
This is really helpful. Thanks a lot.
@LetsKodeItOfficial
@LetsKodeItOfficial 6 жыл бұрын
Glad you liked it :) There is going to be this and additional video in the course.
@manikannanmarimuthu9232
@manikannanmarimuthu9232 6 жыл бұрын
Very Clear explanation. Thanks
@LetsKodeItOfficial
@LetsKodeItOfficial 6 жыл бұрын
Glad you found it helpful :)
@kjuarez29
@kjuarez29 2 жыл бұрын
Love your tutorials and of course your course on Udemy. Thank you so much!
@LetsKodeItOfficial
@LetsKodeItOfficial 2 жыл бұрын
Glad you found it helpful :) Please like and share the video and help us spread the word.
@georgejetson9801
@georgejetson9801 6 жыл бұрын
Thanks. You're the best.
@LetsKodeItOfficial
@LetsKodeItOfficial 6 жыл бұрын
Glad you found it helpful :)
@SyedAbrarHussaini
@SyedAbrarHussaini 3 жыл бұрын
Thank you for the explanation. Consider a scenario where in I've few list boxes(dynamic) on a page, and I need to fill it. The only way to do it is by entering a value and then then clicking outside the box, now the page gets refreshed and then the value gets accepted. How can I tacle this scenario? I tried taking common path, found all the elements and added it to a list and then made it run through a for loop.. but after the first iteration I get stale exception. Any idea about this?
@LetsKodeItOfficial
@LetsKodeItOfficial 3 жыл бұрын
I think I didn't follow the exact scenario you mentioned above. Please feel free to send me your code at letskodeit@gmail.com and I will take a look at it.
@rohitupreti3902
@rohitupreti3902 4 жыл бұрын
Hey thanks for the explanation! For me when I am executing the test cases I am getting this error sometimes and sometimes not. What could be the reason? If the dom is being rebuilt on one run it must be rebuilding on other runs as well since I'm executing the same test script.
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
Hi, It is not feasible to say anything without seeing the website you are working on. Please provide the information and will happy to take a look.
@utkarshabhange4981
@utkarshabhange4981 4 жыл бұрын
Thank you Sir it worked for me
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
Glad you found it helpful, please like and share the video to spread the word.
@chennakesav7134
@chennakesav7134 3 жыл бұрын
well explained the reason behind stale exception. Thankyou. In mycase, I am using page object model where all elements were declared page wise and utilized when required in scripts and am seeing the exception for some of the dropdown fields. Any suggestions for me please
@LetsKodeItOfficial
@LetsKodeItOfficial 3 жыл бұрын
The same concept can be applied to Page Object Model or Page Factory also. Just need to make sure you call the element when needed. It can be a little tricky to explain over a comment but this needs to be considered when designing the framework.
@grandhisetty7381
@grandhisetty7381 6 жыл бұрын
Thank you. What about the stale element exception when we user Page Object Model?
@LetsKodeItOfficial
@LetsKodeItOfficial 6 жыл бұрын
We need to understand the core concept that we should find element when we need it, the same concept can be used in Page Object Model also.
@solomonshepard8531
@solomonshepard8531 3 жыл бұрын
not sure if you guys gives a shit but if you are stoned like me atm you can stream pretty much all the latest movies on InstaFlixxer. I've been streaming with my brother recently =)
@princekristian7301
@princekristian7301 3 жыл бұрын
@Solomon Shepard yea, I've been watching on Instaflixxer for months myself :)
@truejesuschrist
@truejesuschrist 4 жыл бұрын
thank you
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
Glad you found it helpful :) Please like and share the video and help us spread the word.
@Ms-yo2xw
@Ms-yo2xw 2 жыл бұрын
Nice explanation ❤️❤️❤️❤️
@LetsKodeItOfficial
@LetsKodeItOfficial 2 жыл бұрын
Glad you found it helpful, please like and share the video to spread the word :)
@PoojaPatil-vh9le
@PoojaPatil-vh9le 3 жыл бұрын
Hey thank you for the explanation,but I have a doubt, I want to perform an action on that element twice ,so the page needs to be refreshed ,in that scenario ,how to handle that stale element exception .
@LetsKodeItOfficial
@LetsKodeItOfficial 3 жыл бұрын
In that scenario, you need to find elements twice which means find an element perform the 1st action and find the element again before performing the 2nd action.
@lukninja91
@lukninja91 3 жыл бұрын
thank you!!!!!!!!!!!!!
@LetsKodeItOfficial
@LetsKodeItOfficial 3 жыл бұрын
Glad you found it helpful :) Please like and share the video and help us spread the word.
@sushilsawai3661
@sushilsawai3661 3 жыл бұрын
best example
@LetsKodeItOfficial
@LetsKodeItOfficial 3 жыл бұрын
Glad you found it helpful :) Please like and share the video and help us spread the word. Checkout the description to find the complete course details at a very affordable price.
@xiaobaobei1298
@xiaobaobei1298 3 жыл бұрын
Thank yooooooooooooooooooooooooooooooooooooo soooooooooooooooo muuuuuuuuuuuuuuuuch
@LetsKodeItOfficial
@LetsKodeItOfficial 3 жыл бұрын
Glad you found it helpful :) Please like and share the video and help us spread the word.
@pragyasj
@pragyasj 3 жыл бұрын
Hey, are you giving training on udemy for selenium ? Are these covered there as well ? I need a very good training on selenium specially with reading from Excel sheets to enter values on screen for a project
@LetsKodeItOfficial
@LetsKodeItOfficial 3 жыл бұрын
Yes, but the best way to get our latest content is directly. Use one of these links: courses.letskodeit.com/courses/selenium-webdriver-with-java?coupon=KZfaqRS899 courses.letskodeit.com/courses/test-automation-bundle?coupon=KZfaqRS29
@pragyasj
@pragyasj 3 жыл бұрын
@@LetsKodeItOfficial cool ♥️
@hydraulichydra8363
@hydraulichydra8363 3 жыл бұрын
I'm using python, but for me, (and I just figured this out about 45 seconds before commenting this) the problem was I was using an old variable that had just been defined with driver.find_element_by_xpath and clicked, and I reassigned it a new value with driver.find_element_by_xpath so creating a new element with a different name instead of reassigning the old one fixed it. Not really sure why that happened, it seems a little inconsistent (usually when you say variable = whatever then it doesn't matter if it's getting created or reassigned a value) but whatevs. THX for the tutorial.
@LetsKodeItOfficial
@LetsKodeItOfficial 3 жыл бұрын
Glad you were able to figure it out :) And glad the video helped you in some way.
@keithmutamba1395
@keithmutamba1395 3 жыл бұрын
God bless you. You are my hero I fell into the devil’s trap and you saved me
@LetsKodeItOfficial
@LetsKodeItOfficial 3 жыл бұрын
Glad you found it helpful :) Please like and share the video and help us spread the word.
@bcoleone1
@bcoleone1 6 жыл бұрын
Hi anil when using page object model how will you go about this?
@LetsKodeItOfficial
@LetsKodeItOfficial 6 жыл бұрын
We need to understand the core concept and then need to apply in Page Object. When we need to click the element, find before that in Page Object Model also.
@bcoleone1
@bcoleone1 6 жыл бұрын
Let's Kode It remember in page object the page object.init element is called which initialises all elements even before use, and I have also tried re initialising the page object right before its time to interact with the element but it didn’t work
@LetsKodeItOfficial
@LetsKodeItOfficial 6 жыл бұрын
B B -> This is actually Page Factory. In that scenario, if you see an element with stale element exception then you should not find that with Page Factory FindBy annotation and instead find it inside the methods which you may have implemented to perform action on the element.
@KatRollo
@KatRollo 4 жыл бұрын
@@bcoleone1 It means you need to stop using PageFactory. The developers of Selenium regretted ever writing it.
@keskinyavuz
@keskinyavuz 6 жыл бұрын
are these new videos added to udemy as well?
@LetsKodeItOfficial
@LetsKodeItOfficial 6 жыл бұрын
Not yet, they will be 1st added to our own website and then on udemy also after some time.
@ItsCoderDan
@ItsCoderDan 2 жыл бұрын
i still get the exception even after the fix, i cannot seem to find a fix for it because no matter how many checks i give it it always gives a stalemate exception
@LetsKodeItOfficial
@LetsKodeItOfficial 2 жыл бұрын
You can enroll in our course, then you will be able to send your code and get help also as long as the code is on a public website which we can access.
@anilkumaryadav106
@anilkumaryadav106 4 жыл бұрын
How page factory class help in resolving this exception?
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
Can you explain your question? Page Factory class is just a way to implement framework, it does not in resolving this exception.
@anilkumaryadav106
@anilkumaryadav106 4 жыл бұрын
@@LetsKodeItOfficial How .initMethod() helps in resolving stale element reference exception?
@PerpetuoBeats
@PerpetuoBeats 4 жыл бұрын
example on c#? please
@LetsKodeItOfficial
@LetsKodeItOfficial 4 жыл бұрын
You can follow the concept and implement it in any language if you know the concept. Sorry, I don't work with C Sharp.
@birajupatel4540
@birajupatel4540 Жыл бұрын
But in case of data-driven how to handle
@LetsKodeItOfficial
@LetsKodeItOfficial Жыл бұрын
Please explain the issue in detail.
@Shibu11229
@Shibu11229 2 жыл бұрын
Thanks for the explanation. I have a python selenium script that goes to a page, enters data and then clicks a submit button. Another page loads and the script clicks a search button. This is performed through a loop repeatedly and it works for approximately 10-40 times but it always fails at some seemingly random point with the stale element reference exception. I am searching for the button and clicking it on the very next line. Maybe I should try adding the click to the end of the same line where the element is located? SearchButton = WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.button-label'))) SearchButton.click()
@LetsKodeItOfficial
@LetsKodeItOfficial 2 жыл бұрын
Can't be very sure about the issue without running the complete code. But you can always try what you are thinking.
Mystery of StaleElementReferenceException in Selenium WebDriver
18:10
Naveen AutomationLabs
Рет қаралды 50 М.
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 89 МЛН
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 204 МЛН
Пранк пошел не по плану…🥲
00:59
Саша Квашеная
Рет қаралды 7 МЛН
Llegó al techo 😱
00:37
Juan De Dios Pantoja
Рет қаралды 59 МЛН
What is Map and HashMap in Java
16:59
Mukesh otwani
Рет қаралды 35 М.
How to Handle Frames in Selenium WebDriver
21:20
H Y R Tutorials
Рет қаралды 57 М.
How to execute failed test cases in Selenium webdriver
17:09
Mukesh otwani
Рет қаралды 96 М.
Taking ScreenShot ONLY for Failed Tests in Selenium using TestNG Listener
32:12
Naveen AutomationLabs
Рет қаралды 116 М.
Wait for File Download using FluentWait in Selenium
14:54
Naveen AutomationLabs
Рет қаралды 10 М.
Headless Browser Testing using HTMLUnitDriver in Selenium - Session 10
19:53
Naveen AutomationLabs
Рет қаралды 60 М.
Vision Pro наконец-то доработали! Но не Apple!
0:40
ÉЖИ АКСЁНОВ
Рет қаралды 217 М.
📱магазин техники в 2014 vs 2024
0:41
djetics
Рет қаралды 594 М.
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 28 МЛН
Nokia 3310 top
0:20
YT 𝒯𝒾𝓂𝓉𝒾𝓀
Рет қаралды 3,8 МЛН