• <small id='vhPJW'></small><noframes id='vhPJW'>

    <tfoot id='vhPJW'></tfoot>

    <i id='vhPJW'><tr id='vhPJW'><dt id='vhPJW'><q id='vhPJW'><span id='vhPJW'><b id='vhPJW'><form id='vhPJW'><ins id='vhPJW'></ins><ul id='vhPJW'></ul><sub id='vhPJW'></sub></form><legend id='vhPJW'></legend><bdo id='vhPJW'><pre id='vhPJW'><center id='vhPJW'></center></pre></bdo></b><th id='vhPJW'></th></span></q></dt></tr></i><div id='vhPJW'><tfoot id='vhPJW'></tfoot><dl id='vhPJW'><fieldset id='vhPJW'></fieldset></dl></div>
    <legend id='vhPJW'><style id='vhPJW'><dir id='vhPJW'><q id='vhPJW'></q></dir></style></legend>

        • <bdo id='vhPJW'></bdo><ul id='vhPJW'></ul>

      1. Selenium - 过时的元素参考:元素未附加到页面

        Selenium - stale element reference: element is not attached to the page(Selenium - 过时的元素参考:元素未附加到页面)
        <legend id='uFxmS'><style id='uFxmS'><dir id='uFxmS'><q id='uFxmS'></q></dir></style></legend>
        • <bdo id='uFxmS'></bdo><ul id='uFxmS'></ul>

            1. <small id='uFxmS'></small><noframes id='uFxmS'>

                    <tbody id='uFxmS'></tbody>

                • <i id='uFxmS'><tr id='uFxmS'><dt id='uFxmS'><q id='uFxmS'><span id='uFxmS'><b id='uFxmS'><form id='uFxmS'><ins id='uFxmS'></ins><ul id='uFxmS'></ul><sub id='uFxmS'></sub></form><legend id='uFxmS'></legend><bdo id='uFxmS'><pre id='uFxmS'><center id='uFxmS'></center></pre></bdo></b><th id='uFxmS'></th></span></q></dt></tr></i><div id='uFxmS'><tfoot id='uFxmS'></tfoot><dl id='uFxmS'><fieldset id='uFxmS'></fieldset></dl></div>
                  <tfoot id='uFxmS'></tfoot>
                  本文介绍了Selenium - 过时的元素参考:元素未附加到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I am trying to understand why it gives an error while I am trying to display items that took from websites. I am also using google chrome for a browser.

                  chromeDriver.Navigate().GoToUrl("somewebsites");
                  
                  chromeDriver.FindElement(By.Id("something.link.text")).Click();
                  chromeDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
                  

                  And this other parts of my code

                  var item = chromeDriver.FindElementsByXPath("//*[starts-with(@id,"g_1_")]/td[3]/span");
                  foreach (var value in item)
                  {
                      Console.WriteLine(value.Text); 
                  }
                  

                  Whenever I use "chromeDriver.FindElement(By.Id("something.link.text")).Click();", it gives an error. I can't display the data that I pulled.

                  In the error message, It says "OpenQA.Selenium.StaleElementReferenceException: 'stale element reference: element is not attached to the page document". I checked the other posts, but I did not figure it out. How can I solve it?

                  As I read, selenium gives much faster response than website opening time, so it gives the error. Also, rarely, it gives that selenium cannot be located the element. Any suggestion?

                  EDIT: If I remove ".text" from display function, It displays "OpenQA.Selenium.Remote.RemoteWebElement". Does the problems with strings ?

                  EDIT2: I can hold data that I took from websites as like this:

                  [i]="System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]" For this, I wrote something like this:

                  string[] test= new string[100];
                  
                  for (int i = 0; i < 100; i++)
                  {
                       kaan[i] = driver.FindElements(By.XPath("//*[starts-with(@id,"g_1_")]/td[3]/span")).ToString();
                  }
                  

                  How can I convert to the text

                  解决方案

                  I haven't worked in c# but have worked on java/selenium. But,I can give you the idea to overcome staleness.

                  Generally we will be getting the Stale Exception if the element attributes or something is changed after initiating the webelement. For example, in some cases if user tries to click on the same element on the same page but after page refresh, gets staleelement exception.

                  To overcome this, we can create the fresh webelement in case if the page is changed or refreshed. Below code can give you some idea.(It's in java but the concept will be same)

                  Example:

                   webElement element = driver.findElement(by.xpath("//*[@id='StackOverflow']"));
                   element.click();
                   //page is refreshed
                   element.click();//This will obviously throw stale exception
                  

                  To overcome this, we can store the xpath in some string and use it create a fresh webelement as we go.

                  String xpath = "//*[@id='StackOverflow']";
                  driver.findElement(by.xpath(xpath)).click();
                  //page has been refreshed. Now create a new element and work on it
                  driver.findElement(by.xpath(xpath)).click();   //This works
                  

                  In this case, we are collecting a group of webelements and iterating to get the text. But it seems there is some changes in the webelement after collecting the webelements and gettext throws staleness. We can use a loop and create the element on the go and get text.

                  for(int i = 0; i<5; i++)
                  {
                     String value = driver.findElement(by.xpath("//.....["+i+"]")).getText);
                     System.out.println(value);
                  }
                  

                  Hope this helps you. Thanks.

                  这篇关于Selenium - 过时的元素参考:元素未附加到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)
                • <i id='AFGAk'><tr id='AFGAk'><dt id='AFGAk'><q id='AFGAk'><span id='AFGAk'><b id='AFGAk'><form id='AFGAk'><ins id='AFGAk'></ins><ul id='AFGAk'></ul><sub id='AFGAk'></sub></form><legend id='AFGAk'></legend><bdo id='AFGAk'><pre id='AFGAk'><center id='AFGAk'></center></pre></bdo></b><th id='AFGAk'></th></span></q></dt></tr></i><div id='AFGAk'><tfoot id='AFGAk'></tfoot><dl id='AFGAk'><fieldset id='AFGAk'></fieldset></dl></div>

                      <small id='AFGAk'></small><noframes id='AFGAk'>

                      • <bdo id='AFGAk'></bdo><ul id='AFGAk'></ul>
                          <tbody id='AFGAk'></tbody>
                        <tfoot id='AFGAk'></tfoot>
                      • <legend id='AFGAk'><style id='AFGAk'><dir id='AFGAk'><q id='AFGAk'></q></dir></style></legend>