c# - selenium : stale element reference

Visto 155 veces
Saltar al primer mensaje no leído

Nortier David

no leída,
12 ene 2023, 5:44:5812/1/23
a seleniu...@googlegroups.com

Yo girl & man,

 

I’ve a problem (Youston).

 

I find a element, with method : Driver.FindElement(By.XPath(…)
 

Next line, I try: element.click()

 

  • Error :   stale element reference: element is not attached to the page document (Session info: chrome=109.0.5414.74)
    org.openqa.selenium.StaleElementReferenceException

 

Yet the element is still there (in debug I see it)

 

I’ve read some helps on the web, but I don’t understand the problem.

And I don’t know how to solve this problem

 

 

Many many thanks

 

 

  David

 

 


====== DISCLAIMER ======

https://www.cph.be/maildisclaimer

Vinod Tanguturi

no leída,
12 ene 2023, 8:47:3812/1/23
a seleniu...@googlegroups.com
The stale element refers that the Dom has refreshed after you identified the element and before clicking that element. You need to find that element again before the click event and also use a wait statement just in case the page takes time to load.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/217d70c44eb84ebe8a555afdd198de09%40cph.be.

Nortier David

no leída,
13 ene 2023, 3:58:3813/1/23
a seleniu...@googlegroups.com

Thanks for response

 

If I scroll top this element before to click it, is the DOM refreshed ?

 

De : seleniu...@googlegroups.com <seleniu...@googlegroups.com> De la part de Vinod Tanguturi
Envoyé : jeudi 12 janvier 2023 14:47
À : seleniu...@googlegroups.com
Objet : Re: [selenium-users] c# - selenium : stale element reference

Chandrika sai

no leída,
13 ene 2023, 4:28:4613/1/23
a seleniu...@googlegroups.com
Hi...

The element may be inside a frame, you cannot see that frame on web page. 
so once again you identify that element properly, may be it will be inside that frame.

so in the code, you write like, first you need to switch to that frame, and then write locator
to that element, and then you need to click on that element.

Thank you
Chandrika

ebubekir bastama

no leída,
13 ene 2023, 6:50:5013/1/23
a seleniu...@googlegroups.com
I can assist you with C# Selenium in ı am Discord channel live.
https://discord.gg/XbrQyqQw

Chandrika sai <chandrik...@gmail.com>, 13 Oca 2023 Cum, 12:28 tarihinde şunu yazdı:

Anuv4123

no leída,
13 ene 2023, 8:38:4413/1/23
a Selenium-Users
Not sure how your application was developed. You spy the element and try to scroll down and up. If the source in the inspect element screen has any reload happens then it means your dom got refreshed. Just to be safe try to find element before click and see if that works 

Thanks



Hamim Alam

no leída,
15 ene 2023, 23:17:3515/1/23
a Selenium Users
Usually in this kind of situation you might want use something like retry and click. I have written below function in JAVA which you can take reference of.

```
public static boolean retryingFindClick(WebDriver driver, String ele) {
        boolean result = false;
        int attempts = 0;
        while(attempts < 2) {
            try {
                driver.findElement(By.xapth(ele)).click();
                result = true;
                break;
            } catch(NoSuchElementException e) {
            }
            attempts++;
        }
        return result;
    }
```

Hope this helps!!!

Ayush Yadav

no leída,
15 ene 2023, 23:17:3515/1/23
a Selenium Users
Hey man, 
You can also use waits in selenium and make use of Presence of element detected function.
For example in python, use:
  WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".reply-button"))).click()
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos