0

I have a page with 50 entries inside and I need to navigate to each one of them one by one. The exception is being thrown after I come back from first one and try to navigate to a 2nd one. After googling for a while I see that it might be because the instance of the main page was deleted. I am using foreach loop and would like the code to continue. the code looks like this:

IReadOnlyCollection<IWebElement> anchors = this.driverIpass.FindElements(By.CssSelector(".card-list-item.ng-scope"));
            foreach (IWebElement anchor in anchors)
            {
                anchor.FindElement(By.XPath("//*[contains(@id,'workitem-goto-tablet-btn')]")).Click();

                //below is test button to go back
                driverIpass.FindElement(By.Name("editForm:j_idt693")).Click();

            }

As you can see all im trying to do here is go in then back for every item in the collection. I am very new to all of this, could someone please put me on the right path ? Thank you

Radas
  • 45
  • 7

1 Answers1

0

Try keeping a list of the ids and looping through that instead of the anchors collection which goes stale.

terrencep
  • 675
  • 5
  • 16
  • thanks, ill try that. can you tell me the difference between the list and what i've done here so i could better understand it? – Radas Dec 02 '20 at 02:24
  • The webelement is some how aware the page was navigated. See this https://stackoverflow.com/a/45003230/10491171 – terrencep Dec 02 '20 at 02:32
  • This is actualy correct. But the reason is: when you come "back" to the first page, the DOM will be rewritten, causing your previously fetched webElement references to become stale. See https://www.selenium.dev/exceptions – DMart Dec 02 '20 at 04:27