• Register
0 votes
866 views

Problem :

I have the list which has the multiple links under each section. Each section has the same links I need to click the particular link under each section. I have written my code for it but when I execute the code it gives me below error:

Exception in thread "main" 
org.openqa.selenium.StaleElementReferenceException: stale element 
reference: element is not attached to the page document

 

7 5 2
3,870 points

2 Answers

0 votes

Solution :

A reason for this error is because a element to which you have referred is removed from a DOM structure

I was facing a same problem while working with IEDriver. A reason was because javascript loaded my element one more time after I have referred so my date reference pointed to the unexisting object even if it was right their on the UI. I used a below workaround.

try {
WebElement date = driver.findElement(By.linkText(Utility.getSheetData(path, 7, 1, 2)));
date.click();
}
catch(org.openqa.selenium.StaleElementReferenceException ex)
{
WebElement date = driver.findElement(By.linkText(Utility.getSheetData(path, 7, 1, 2)));
date.click();
}

See if above workaround can help you !

OR

The thing here is that you are trying to use a for loop outside of the conditional statement.

After a conditions in your IF statement are met you probably navigate to the another page, so when a for loop attempts to iterate once more, then you get a stale element error because now you are on the different page.

You can add the break at the end of the if statement, this really worked for me.

9 7 4
38,600 points
0 votes

Solution:

In this article we will learn how to avoid state element reference problems. Sometimes this may happen for the wrong path directory from input. We experiment with some of the code methods that may be fit for the environment or system you. Although there is no straightforward solution for something like this, since it is a content specific problem.

Reason:

 We can assume your calling function has not been deleted as you can see it.

So we are managing with the second case. This usually means that the page is reloading in between you locating the element in the server. Hence your interaction with the element. To debug this - put a breakpoint on the

Error occurs for example when you have a web element reference and the document it was retrieved from navigates. After navigation, all web element references to the previous document will be discarded along with the document. This will cause any ambiguous coding with the web element to fail with the stale element reference error.

Finally we overcome the static problem by some input activity the keyword dropdown manual view. There we will make a script that fetches the document.

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 14 views
14 views
Problem: I am very new to Selenium and Java both. I am trying to select and get the dropdown value in a Selenium WebDriver using the Java. The HTML Code is as below: <select class="form_input_select bx-def-font" name="Sex[0]"> <option value="Male">Man</option> < ... it only shows _Others Kindly help me to solve above issue. I am unable to fix above issue after working on it for more than 3 days.
asked Jul 9 Raphael Pacheco 4.9k points
0 votes
1 answer 9 views
9 views
I am finding a program that will help me to handle multiple windows in Selenium Webdriver.
asked Oct 5 Daniel Anderson 4k points
1 vote
1 answer 492 views
492 views
Problem : I am not completely expert in Python, but still I am willing to learn good practices while I develop my skills. I am trying to remove the high and low values from the list of numbers, I know how to do this , but I want to know the better way to do this. myrawlist = [ ... 2, 3, 4] mytrimmedlist = mylist[1:-1] #[1, 2, 3] I get the required output, but looking for the better way to do this.
asked Dec 14, 2019 alecxe 7.5k points
1 vote
1 answer 25 views
25 views
Problem: I was trying to check if an element does exist in a list using a pyhton program: primary_list = [ 10, 12, 16, 6, 20, 33 ] a = input("Please enter a number to check if this exists in the list: ") print("Checking if input exists in this list : ") for ... not giving any output that is right. What should I do to fix this and how to check if an element does exist in a list. Thanks in advance.
asked May 16 samhaz 5k points