1

这是我正在处理的代码片段

if (!(strGCID.Substring(0, 3) == "BBP"))
{
    string strDate;

    Span spn = ie.Span(Find.ById("detail_page_section_1_section_b"));
    for (int x = 1; x < 12; x++)
    {
        strDate = spn.TableCells[x].Text;
        if (strDate.IndexOf("AM") > 0 || strDate.IndexOf("PM") > 0)
        {
            txtPurchaseDate.Text = DateTime.Parse(strDate).ToString("MM/dd/yyyy");
            break;
        }
    }
}

基本上,如果我在以“strDate = spn.Table”开头的行设置了一个断点,我的程序实际上会按照它应该的方式工作,并且我会在 span 块中找到数据。如果我删除断点,我会得到一个数组的索引错误,我尝试通过表格单元格查找日期。我一直盯着代码,不知道为什么会发生这种情况。在这一点上,我认为最简单的事情就是不要费心在页面上查找日期。问题是,我没有看到什么?

4

1 回答 1

2

您可能需要调用 WaitUntilExists...

Span spn = ie.Span(Find.ById("detail_page_section_1_section_b"));
spn.WaitUntilExists();
for (...

于 2012-12-13T16:16:06.397 回答