3

受け入れテストに Watin を使用していますが、HTML ソースが 100K を超える Web ページがあると、非常に遅くなることがわかりました。

速度の問題のいくつかは、HTML テーブルの反復処理に起因していると感じています。一部のテーブルには 50 ~ 60 の行があり、それぞれに 5 ~ 10 の列があります。これにより、ページ上のアイテムを検索するときに Watin が非常に遅くなります。

使用する要素検索メソッドの最適なオーバーロード (たとえば) に関する具体的な推奨事項はありますか? 本当に遅いので避けるべき特定の方法はありますか?

4

3 に答える 3

3

Table要素の処理を高速化するために私が行ったことは、低速になる可能性のある.TableRowsプロパティを呼び出す代わりに、テーブル行でNextSiblingを呼び出すことにより、テーブル行を反復処理する拡張メソッドです。

public static class IElementContainerExtensions
{
    /// <summary>
    /// Safely enumerates over the TableRow elements contained inside an elements container.
    /// </summary>
    /// <param name="container">The IElementsContainer to enumerate</param>
    /// <remarks>
    /// This is neccesary because calling an ElementsContainer TableRows property can be an
    /// expensive operation.  I'm assuming because it's going out and creating all of the
    /// table rows right when the property is accessed.  Using the itterator pattern below
    /// to prevent creating the whole table row hierarchy up front.
    /// </remarks>
    public static IEnumerable<TableRow> TableRowEnumerator( this IElementContainer container )
    {
        //Searches for the first table row child with out calling the TableRows property
        // This appears to be a lot faster plus it eliminates any tables that may appear
        // nested inside of the parent table

        var tr = container.TableRow( Find.ByIndex( 0 ) );
        while ( true )
        {
            if ( tr.Exists )
            {
                yield return tr;
            }
            //Moves to the next row with out searching any nested tables.
            tr = tr.NextSibling as TableRow;
            if ( tr == null || !tr.Exists )
            {
                break;
            }
        }
    }
}

テーブルへの参照を取得するだけで、最初のtrが検出され、そのすべての兄弟が繰り返されます。

foreach ( TableRow tr in ie.Table( "myTable" ).TableRowEnumerator() )
{
    //Do Someting with tr
}
于 2010-02-08T15:22:32.943 に答える
1

HTML テーブルの行要素または列要素に ID を追加すると、少し高速化できます。したがって、列が少ない場合は、少なくとも列にIDを追加する方がおそらく簡単です。(特に、行数がおそらく変化しているため)。

だから代わりに

string price = ie.Table(Find.ById("name")).TableRows[i].TableCells[i].Text;

この変更により、html

<table id="name">
<tr id='total'>             
            <td id='price'>
                $1.00
            </td>
        </tr>
</table>

繰り返しなし

string total = ie.TableRow(Find.ByID("total")).TableCell(Find.ById("price")).Text;

または1回だけの繰り返し

ie.Table(Find.ById("name")).TableRows[i].TableCell(Find.ById("price")).Text;
于 2009-08-03T10:25:12.813 に答える
0

Watin のパフォーマンスに関するちょっとしたメモですが、特定のコード フラグメントによって、watin プログラムの速度が大幅に低下することがわかりました (理由はわかりません)。私はそれについてここに書きました:

http://me-ol-blog.blogspot.co.il/2011/08/some-thoughts-about-watin-windows-7.html

于 2012-08-30T10:30:40.843 に答える