title: Iterating through website table (Element is not attached to the page document)
body: <p>I have a code that iterates through website table. Table is dynamic and items are loaded into it on user scroll.</p>
  <p>I have parameters:</p>
  <pre><code>public class UserTableRow
  {
      private readonly IWebElement row;
  
      public string Username =&gt; row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l0 r0')]&quot;)).Text;
      public string Firstname =&gt; row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l1 r1')]&quot;)).Text;
      public string Lastname =&gt; row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l2 r2')]&quot;)).Text;
      public string Type =&gt; row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l3 r3')]&quot;)).Text;
      public string Crew =&gt; row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l4 r4')]&quot;)).Text;
      public string JobTitle =&gt; row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l5 r5')]&quot;)).Text;
      public string DefaultPrice =&gt; row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l6 r6')]&quot;)).Text;
      public string Future =&gt; row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l7 r7')]&quot;)).Text;
      public string Language =&gt; row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l8 r8')]&quot;)).Text;
  
      public override string ToString()
      {
          return &quot;SharePrice: &quot; + Username.ToString() + &quot;: &quot; + Firstname.ToString();
      }
  
      public UserTableRow(IWebElement row)
      {
          try
          {
              this.row = row;
          }
          catch (Exception)
          {
  
              throw;
          }
      }
  }
  </code></pre>
  <p>Here is the method itself for adding data into List.</p>
  <pre><code>    public static IEnumerable&lt;UserTableRow&gt; AddItemsToList(IWebDriver driver)
      {
  
          IReadOnlyCollection&lt;IWebElement&gt; rows = new List&lt;IWebElement&gt;();
  
          List&lt;UserTableRow&gt; DataHere = new List&lt;UserTableRow&gt;();
  
          driver.FindElement(By.XPath(&quot;//*[@id=\&quot;disabled_users_show_label\&quot;]&quot;)).Click();
  
          Thread.Sleep(7000);
  
          driver.FindElement(By.XPath(&quot;//*[@id=\&quot;users_table\&quot;]/div[5]/div/div[1]&quot;)).Click();
  
          for (int i = 0; i &lt; 11; i++)
          {
              rows = driver.FindElements(By.CssSelector(&quot;#users_table .slick-viewport .slick-row&quot;));
  
              // Now we will iterate through cells in table and compare to what we already have in the list
              foreach (IWebElement cell in rows)
              {
                  rows = driver.FindElements(By.CssSelector(&quot;#users_table .slick-viewport .slick-row&quot;));
  
                  // Add data to our object
                  DataHere.Add(new UserTableRow(cell));
  
                  //We need to select table first to be able to scroll down. We do it directly here
                  Actions actions = new Actions(driver);
                  actions.SendKeys(Keys.ArrowDown).Build().Perform();
  
              }
  
          }
  
          List&lt;UserTableRow&gt; noDupes = DataHere.Distinct().ToList();
  
          return noDupes;
      }
  </code></pre>
  <p>It goes fine but at some point (I don't know why) it catches an error saying:</p>
  <blockquote>
  <p>OpenQA.Selenium.StaleElementReferenceException: 'stale element
  reference: element is not attached to the page document   (Session
  info: chrome=84.0.4147.105)'</p>
  </blockquote>
  <p>Pointing at <code>row.FindElement(By.XPath(&quot;.//div[contains(@class, 'slick-cell l0 r0')]&quot;)).Text;</code></p>
  <p>Any ideas how to add try catch to Parameters so code will continue execution until adding to list has been finished?</p>
  <hr />
  <p>The reason I am calling</p>
  <pre><code>rows = driver.FindElements(By.CssSelector(&quot;#users_table .slick-viewport .slick-row&quot;));
  </code></pre>
  <p>Inside the loop is I am trying to update table values to iterate through after scrolling down. This is a tricky table that unloads items and loads other items from database on the scroll. So I am trying to mimic user scroll with keyboard and catch table items to List.</p>
  <p>It would be perfect to compare to list items on the flight. However I was thinking to get all to the List (even duplicates) and then later make other list where I will eliminate duplicates wit something like:</p>
  <pre><code>    List&lt;UserTableRow&gt; noDupes = DataHere.Distinct().ToList();
  </code></pre>
  <p>HTML:</p>
  <pre><code>&lt;div id=&quot;users_table&quot; class=&quot;security_slick_container slickgrid_300610 ui-widget&quot; style=&quot;overflow: hidden; outline: 0px; position: relative;&quot;&gt;
      &lt;div tabindex=&quot;0&quot; hidefocus=&quot;&quot; style=&quot;position:fixed;width:0;height:0;top:0;left:0;outline:0;&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;slick-header ui-state-default&quot; style=&quot;overflow:hidden;position:relative;&quot;&gt;
          &lt;div class=&quot;slick-header-columns&quot; style=&quot;left: -1000px; width: 2132px;&quot; unselectable=&quot;on&quot;&gt;
              &lt;div class=&quot;ui-state-default slick-header-column slick-header-sortable slick-header-column-sorted&quot; id=&quot;slickgrid_300610userName&quot; title=&quot;&quot; style=&quot;width: 94px;&quot;&gt;&lt;span class=&quot;slick-column-name&quot;&gt;&lt;strong&gt;Username:&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;slick-sort-indicator slick-sort-indicator-asc&quot;&gt;&lt;/span&gt;
                  &lt;div class=&quot;slick-resizable-handle&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-state-default slick-header-column slick-header-sortable&quot; id=&quot;slickgrid_300610firstName&quot; title=&quot;&quot; style=&quot;width: 89px;&quot;&gt;&lt;span class=&quot;slick-column-name&quot;&gt;&lt;strong&gt;Firstname:&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;slick-sort-indicator&quot;&gt;&lt;/span&gt;
                  &lt;div class=&quot;slick-resizable-handle&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-state-default slick-header-column slick-header-sortable&quot; id=&quot;slickgrid_300610lastName&quot; title=&quot;&quot; style=&quot;width: 109px;&quot;&gt;&lt;span class=&quot;slick-column-name&quot;&gt;&lt;strong&gt;Lastname:&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;slick-sort-indicator&quot;&gt;&lt;/span&gt;
                  &lt;div class=&quot;slick-resizable-handle&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-state-default slick-header-column slick-header-sortable&quot; id=&quot;slickgrid_300610type&quot; title=&quot;&quot; style=&quot;width: 124px;&quot;&gt;&lt;span class=&quot;slick-column-name&quot;&gt;&lt;strong&gt;Type:&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;slick-sort-indicator&quot;&gt;&lt;/span&gt;
                  &lt;div class=&quot;slick-resizable-handle&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-state-default slick-header-column slick-header-sortable&quot; id=&quot;slickgrid_300610crew&quot; title=&quot;&quot; style=&quot;width: 109px;&quot;&gt;&lt;span class=&quot;slick-column-name&quot;&gt;&lt;strong&gt;Crew:&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;slick-sort-indicator&quot;&gt;&lt;/span&gt;
                  &lt;div class=&quot;slick-resizable-handle&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-state-default slick-header-column slick-header-sortable&quot; id=&quot;slickgrid_300610jobTitle&quot; title=&quot;&quot; style=&quot;width: 109px;&quot;&gt;&lt;span class=&quot;slick-column-name&quot;&gt;&lt;strong&gt;Job title:&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;slick-sort-indicator&quot;&gt;&lt;/span&gt;
                  &lt;div class=&quot;slick-resizable-handle&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-state-default slick-header-column slick-header-sortable&quot; id=&quot;slickgrid_300610defaultPriceClass&quot; title=&quot;&quot; style=&quot;width: 124px;&quot;&gt;&lt;span class=&quot;slick-column-name&quot;&gt;&lt;strong&gt;Defaultprice class:&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;slick-sort-indicator&quot;&gt;&lt;/span&gt;
                  &lt;div class=&quot;slick-resizable-handle&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-state-default slick-header-column&quot; id=&quot;slickgrid_300610description&quot; title=&quot;&quot; style=&quot;width: 129px;&quot;&gt;&lt;span class=&quot;slick-column-name&quot;&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/span&gt;
                  &lt;div class=&quot;slick-resizable-handle&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-state-default slick-header-column&quot; id=&quot;slickgrid_300610language&quot; title=&quot;&quot; style=&quot;width: 39px;&quot;&gt;&lt;span class=&quot;slick-column-name&quot;&gt;&lt;strong&gt;Language:&lt;/strong&gt;&lt;/span&gt;
                  &lt;div class=&quot;slick-resizable-handle&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;slick-headerrow ui-state-default&quot; style=&quot;overflow: hidden; position: relative; display: none;&quot;&gt;
          &lt;div class=&quot;slick-headerrow-columns&quot; style=&quot;width: 1115px;&quot;&gt;&lt;/div&gt;
          &lt;div style=&quot;display: block; height: 1px; position: absolute; top: 0px; left: 0px; width: 1132px;&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;slick-top-panel-scroller ui-state-default&quot; style=&quot;overflow: hidden; position: relative; display: none;&quot;&gt;
          &lt;div class=&quot;slick-top-panel&quot; style=&quot;width:10000px&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;slick-viewport&quot; style=&quot;width: 100%; overflow: auto; outline: 0px; position: relative; height: 567px;&quot;&gt;
          &lt;div class=&quot;grid-canvas&quot; style=&quot;height: 16550px; width: 1115px;&quot;&gt;
              &lt;div class=&quot;ui-widget-content slick-row even&quot; style=&quot;top:0px&quot;&gt;
                  &lt;div class=&quot;slick-cell l0 r0&quot;&gt;john.smith&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l1 r1&quot;&gt;John&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l2 r2&quot;&gt;Smith&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l3 r3&quot;&gt;Contractor&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l4 r4&quot;&gt;Microsoft&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l5 r5&quot;&gt;Sales manager&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l6 r6&quot;&gt;A&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l7 r7&quot;&gt;&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l8 r8&quot;&gt;en&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-widget-content slick-row odd&quot; style=&quot;top:25px&quot;&gt;
                  &lt;div class=&quot;slick-cell l0 r0&quot;&gt;robert.geits&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l1 r1&quot;&gt;Robert&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l2 r2&quot;&gt;Geits&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l3 r3&quot;&gt;Staff&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l4 r4&quot;&gt;Google&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l5 r5&quot;&gt;Project manager&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l6 r6&quot;&gt;B&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l7 r7&quot;&gt;&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l8 r8&quot;&gt;de&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;ui-widget-content slick-row even&quot; style=&quot;top:50px&quot;&gt;
                  &lt;div class=&quot;slick-cell l0 r0&quot;&gt;amir.rooney&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l1 r1&quot;&gt;Amir&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l2 r2&quot;&gt;Rooney&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l3 r3&quot;&gt;Staff&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l4 r4&quot;&gt;Microsoft&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l5 r5&quot;&gt;Sales manager&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l6 r6&quot;&gt;A&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l7 r7&quot;&gt;&lt;/div&gt;
                  &lt;div class=&quot;slick-cell l8 r8&quot;&gt;en&lt;/div&gt;
              &lt;/div&gt;
              # ETC # ETC # ETC # ETC # ETC # ETC # ETC # ETC # ETC # ETC 
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div tabindex=&quot;0&quot; hidefocus=&quot;&quot; style=&quot;position:fixed;width:0;height:0;top:0;left:0;outline:0;&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>