Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:56:29+00:00 2026-06-10T17:56:29+00:00

I am having an issue with navigation. I get a list of rows from

  • 0

I am having an issue with navigation. I get a list of rows from an html table. I iterate over the rows and scrape information from them. But there is also a link on the row that I click to go to more information related to the row to scrape. Then I navigate back to the page with the original table. This works for the first row, but for the subsequent rows, it throws an exception.

I look at my row collection after the first time the link inside a row is clicked, and none of them have the correct values like they did before I clicked the link. I believe that there is something going on when I navigate to a different URL that I’m not getting.

My code is below. How do I get this working so I can iterate over the parent table, click the links in each row, navigate to the child table, but still continue iterating over the rows in the parent table?

    private List<Document> getResults()
    {
        var documents = new List<Document>();

        //Results
        IWebElement docsTable = this.webDriver.FindElements(By.TagName("table"))
            .Where(table => table.Text.Contains("Document List"))
            .FirstOrDefault();

        var validDocRowRegex = new Regex(@"^(\d{3}\s+)");

        var docRows = docsTable.FindElements(By.TagName("tr"))
            .Where(row =>
                //It throws an exception with .FindElement() when there isn't one.
                row.FindElements(By.TagName("td")).FirstOrDefault() != null &&
                    //Yeah, I don't get this one either. I negate the match and so it works??
                !validDocRowRegex.IsMatch(
                    row.FindElement(By.TagName("td")).Text))
            .ToList();

        foreach (var docRow in docRows)
        {
            //Todo: find out why this is crashing on some documents.
            var cells = docRow.FindElements(By.TagName("td"));

            var document = new Document
            {
                DocID = Convert.ToInt32(cells.First().Text),
                PNum = Convert.ToInt32(cells[1].Text),
                AuthNum = Convert.ToInt32(cells[2].Text)
            };

            //Go to history for the current document.
            cells.Where(cell =>
                cell.FindElements(By.TagName("a")).FirstOrDefault() != null)
                .FirstOrDefault().Click();

            //Todo: scrape child table.

            this.webDriver.Navigate().Back();
        }

        return documents;
    }

UPDATE: (In response to Jim Evans’ answer)

This looks like it’s working correctly.

private List<Document> getResults()
    {
        var documents = new List<Document>();
        IWebElement docRow = null;
        int rowIndex = 0;

        while((docRow = this.getDocumentRow(rowIndex)) != null)
        {
            var cells = docRow.FindElements(By.TagName("td"));

            var document = new Document
        {
            DocID = Convert.ToInt32(cells.First().Text),
            PNum = Convert.ToInt32(cells[1].Text),
            AuthNum = Convert.ToInt32(cells[2].Text)
        };

            //Go to history for the current document.
            cells.Where(cell =>
                cell.FindElements(By.TagName("a")).FirstOrDefault() != null)
                .FirstOrDefault().Click();

            //Todo: scrape child table.

            this.webDriver.Navigate().Back();

            documents.Add(well);

            rowIndex++;
        }

        return documents;
    }

    private IWebElement getDocumentRow(int rowIndex)
    {
        try
        {
            IWebElement docsTable = this.webDriver.FindElements(By.TagName("table"))
                .Where(table => table.Text.Contains("Document List"))
                .FirstOrDefault();

            var validDocRowRegex = new Regex(@"^(\d{3}\s+)");

            var docRow = docsTable.FindElements(By.TagName("tr"))
                .Where(row =>
                    //It throws an exception with .FindElement() when there isn't one.
                    row.FindElements(By.TagName("td")).FirstOrDefault() != null &&
                        //Yeah, I don't get this one either. I negate the match and so it works??
                    !validDocRowRegex.IsMatch(
                        row.FindElement(By.TagName("td")).Text))
                .ElementAt(rowIndex);

            return docRow;
        }
        catch
        {
            return null;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:56:31+00:00Added an answer on June 10, 2026 at 5:56 pm

    Your problem is that once you navigate to a new page (via .Click() in your case), your cached elements are no longer valid. The DOM is reconstructed on every page load, including when you navigate back in the browser history. So even though you’re loading a page you’ve already navigated to, you’re getting a newly constructed DOM, so all references to the previously-constructed DOM are invalid. The solution is to re-find the elements you’re looking for after you navigate back to the previous page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having weird issue during application relaunch, I get two Navigation Bars when I
Having issue with slider navigation. Works perfectly fine when there are no other unordered
Hi guys I am having issue I have this query: SELECT * FROM useraccount
I am having an issue submitting $_POST Data from a form located in a
I'm having a menu spacing issue in IE7 and IE6 that I cannot get
Trying out some things with php and html, I'm having issues trying to get
I posted a similar question earlier, but I was having an issue with getting
Having issues with Twitter Bootstrap responsive navigation. The best way to explain this is
Im having a very sneaky issue in Xcode and its Log Navigator. I've recreated
I having issue that content assistant / intellisense is working in methods such as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.