How To Handle Stale Element Exception - Selenium WebDriver Tutorial

preview_player
Показать описание
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

****************************************************************
Complete Test Automation Bundle ($29.99 Only):
Includes 9 Courses, future new test and automation courses will be added to this bundle

****************************************************************
Selenium WebDriver With Java ($8.99 Only):

****************************************************************
Selenium WebDriver With Python ($8.99 Only):

****************************************************************
Selenium WebDriver Bundle ($19 Only):

****************************************************************
Please be our Patron and support us to provide you great content:

Website:

Join Private Facebook Group:

Follow us on Facebook and Twitter for technology updates:
Рекомендации по теме
Комментарии
Автор

Bhai sahab ne 5 min me sikha diya !!! Very well explained .... Thankyou so much

MumPuneMum
Автор

This is an on-the-right-path video on the topic. Not suggesting hacky workarounds like try-catch.

KatRollo
Автор

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

kiwihour
Автор

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

ItsCoderDan
Автор

This is nice, short and easy example to understand that exception. Really nice work.

ifelse
Автор

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 .

PoojaPatil-
Автор

easily the best explanation of stale exception I've found, thank you!

mmat_
Автор

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()

Shibu
Автор

Love your tutorials and of course your course on Udemy. Thank you so much!

kjuarez
Автор

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

chennakesav
Автор

Thank you. What about the stale element exception when we user Page Object Model?

grandhisetty
Автор

God bless you. You are my hero I fell into the devil’s trap and you saved me

keithmutamba
Автор

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?

SyedAbrarHussaini
Автор

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

pragyasj
Автор

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.

hydraulichydra
Автор

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.

rohitupreti
Автор

you are doing great. No one is so helpful. Please continue to upload videos

irtifakhan
Автор

Hi anil when using page object model how will you go about this?

bcoleone
Автор

But in case of data-driven how to handle

birajupatel
Автор

are these new videos added to udemy as well?

keskinyavuz