0

我正在自动化网页编辑任务。该网页在框架内有一个动态表格。每行有五列。动态表是指在网页上动态加载行。在任何给定点,加载的行数都不超过 22。我可以通过移动滚动条访问更多行。表中的总行数约为 450,我需要读取所有行以修改第 2 列中的一些值。我目前正在使用 Selenium WebDriver 尝试将行读入 List,但只能接收 22 行在任何给定时间。这是我尝试过的:

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

有什么方法可以将整个表(450 行)读入数据结构,以便对它们进行内存处理?

这是通过 FireBug 的 HTML 部分的样子:

    <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;">
4

1 回答 1

-1

“在任何给定点,加载的行数不超过 22”

这意味着 selenium 只能访问 22 行并将其存储到 LIST 数据结构中,因为浏览器只有 22 行。

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

您提到您可以通过滚动访问更多行,包括一个可以触发滚动事件的函数。利用 Thread.sleep(毫秒); 如果页面内容加载缓慢。如果您需要更多信息,请告诉我,也请分享代码

于 2015-04-20T10:50:36.767 回答