简体   繁体   中英

Get all rows from a dynamic table using Selenium WebDriver

I am working on automating a webpage editing task. The webpage has a dynamic table inside a frame. Each row has five columns. By dynamic table I mean that the rows are loaded dynamically on the web page. At any given point, the number of rows loaded are not more than 22. I can access more rows by moving the scroll bar. The total number of rows in the table is ~450, and I need to read all of them to modify some values in Column 2. I am currently using Selenium WebDriver to try to read the rows into a List, but can only receive 22 rows at any given time. Here is what I have tried:

        IWebElement tableElement = Driver.driverInstance.FindElement(By.XPath(*tableXPath*));
        var rowList = tableElement.FindElements(By.TagName("tr"));
        Console.WriteLine("Table rows: " + rowList.Count());

Is there any way by which I can read the entire table(450 rows) into a data structure, so I can do in-memory processing on them?

This is how the HTML portion looks like, through FireBug:

    <table id="ctl00_MPH_HyperGrid1ContentTable" class="HyperGrid" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
    <tr id="ctl00_MPH_HyperGrid1_10" class="" style="height: 37px;">
    <tr id="ctl00_MPH_HyperGrid1_11" class="alt" style="height: 37px;">
    <tr id="ctl00_MPH_HyperGrid1_12" class="" style="height: 37px;">
        <td class="checkable">
        <td class="">AntelopeEB</td>
        <td class="">CA - Antelope EB</td>
        <td class="">SmarterMail</td>
        <td class="">User</td>
        <td class="">
        <td class="loadingCell" colspan="5" style="display:none;">Loading...</td>
    </tr>
    <tr id="ctl00_MPH_HyperGrid1_13" class="alt" style="height: 37px;">
    <tr id="ctl00_MPH_HyperGrid1_14" class="" style="height: 37px;">

"At any given point, the number of rows loaded are not more than 22"

That means only 22 rows can be accessed by selenium and stored into the LIST datastructure as the browser has only 22 rows.

You need to trigger an event through SELENIUM to make the remaining data to appear in the browser, so that selenium can retrieve the next 22 tags.

You've mentioned that you can access more rows by scrolling, include a function that can trigger the scrolling event. Make use of Thread.sleep(millisecs); if page content loading is slow. Let me know if you need more info, please share the code too

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM