简体   繁体   English

使用 Selenium WebDriver 从动态表中获取所有行

[英]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.在任何给定点,加载的行数不超过 22。我可以通过移动滚动条访问更多行。 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.表中的总行数约为 450,我需要读取所有行以修改第 2 列中的一些值。我目前正在使用 Selenium WebDriver 尝试将行读入列表,但只能接收 22 行在任何给定的时间。 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?有什么方法可以将整个表(450 行)读入数据结构,以便对它们进行内存处理?

This is how the HTML portion looks like, through FireBug:这是 HTML 部分的样子,通过 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" “在任何给定点,加载的行数不超过 22”

That means only 22 rows can be accessed by selenium and stored into the LIST datastructure as the browser has only 22 rows.这意味着 selenium 只能访问 22 行并存储到 LIST 数据结构中,因为浏览器只有 22 行。

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.你需要通过SELENIUM触发一个事件,让剩余的数据出现在浏览器中,这样selenium才能检索到接下来的22个标签。

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);利用 Thread.sleep(millisecs); if page content loading is slow.如果页面内容加载缓慢。 Let me know if you need more info, please share the code too如果您需要更多信息,请告诉我,也请分享代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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