2016-05-13 4 views
0

ページには3つの列があり、日付順にソートするボタンがページにあります。私は運がないとこれを把握しようとしています。以下は1レコードの例です。ページにはこれらのうち50個が存在することがあります。並べ替えSeleniumオブジェクトC# - テーブルではありません

3つの「列」をすべて配列に取得し、出力を昇順または降順で並べ替えるにはどうすればよいですか?次にソート値をクリックして新しい配列リストを取得して比較することができます。 findElements * .toListを実行すると、すべての行のリストが表示されますが、並べ替えるには日付フィールドを識別できません。

私は何が欠けていますか?

 |*444577233 444577233 (WORK 555.123.4567)* | *Voicemail (1 min 49 sec)* | *Apr 09, 2016 09:42 AM*| 

     <div class="full-mailbox-message alert alert-warning" style="display: none;"> 
     <div id="message-list" class="message-list message-list-scroll"> 
     <div class="list-item filterable message-item js-message-item cp " data-id="9408"> 
     <span class="inline"> 
     <input class="custom js-message-item-checkbox" type="checkbox"> 
     <label></label> 
     </span> 
     <span class=" " data-id="9408"> 
     <i class="message-list-icon icon-voice-mail custom-icon"></i> 
     <span class="sender" data-phone="5555551759" title="CONPORT 010,CR3522">CONPORT 010,CR3522 (555.555.1759)</span> 
     <span class="time" title="Apr 08, 2016 07:30 PM">Apr 08, 2016 07:30 PM</span> 
     <span class="summary"> 
     <span class="text"> Voicemail (57 sec) </span> 
     </span> 
     </span> 
     </div> 
     <div class="list-item filterable message-item js-message-item cp " data-id="8592"> 
     <span class="inline"> 
     <input class="custom js-message-item-checkbox" type="checkbox"> 
     <label></label> 
     </span> 
     <span class=" " data-id="8592"> 
     <i class="message-list-icon icon-voice-mail custom-icon"></i> 
     <span class="sender" data-phone="5555551759" title="CONPORT 010,CR3522">CONPORT 010,CR3522 (555.555.1759)</span> 
     <span class="time" title="Mar 28, 2016 08:31 PM">Mar 28, 2016 08:31 PM</span> 
     <span class="summary"> 
     <span class="text"> Voicemail (7 sec) </span> 
     </span> 
     </span> 
     </div> 
     <div class="list-item filterable message-item js-message-item cp " data-id="8523"> 
     <span class="inline"> 
     <input class="custom js-message-item-checkbox" type="checkbox"> 
     <label></label> 
     </span> 
     <span class=" " data-id="8523"> 
     <i class="message-list-icon icon-voice-mail custom-icon"></i> 
     <span class="sender" data-phone="5555551754" title="CONPORT 005,CR3522">CONPORT 005,CR3522 (555.555.1754)</span> 
     <span class="time" title="Mar 27, 2016 11:45 PM">Mar 27, 2016 11:45 PM</span> 
     <span class="summary"> 
     <span class="text"> Voicemail (7 sec) </span> 
     </span> 
     </span> 
     </div> 
     <div class="list-item filterable message-item js-message-item cp " data-id="8477"> 
     <span class="inline"> 
     <input class="custom js-message-item-checkbox" type="checkbox"> 
     <label></label> 
     </span> 
     <span class=" " data-id="8477"> 
     <i class="message-list-icon icon-voice-mail custom-icon"></i> 
     <span class="sender" data-phone="withheld" title="Identity withheld">Identity withheld (withheld)</span> 
     <span class="time" title="Mar 24, 2016 03:51 AM">Mar 24, 2016 03:51 AM</span> 
     <span class="summary"> 
     <span class="text"> Voicemail (1 sec) </span> 
     </span> 
     </span> 
     </div> 
     <div class="list-item filterable message-item js-message-item cp " data-id="8470"> 
     <span class="inline"> 
     <input class="custom js-message-item-checkbox" type="checkbox"> 
     <label></label> 
     </span> 
     <span class=" " data-id="8470"> 
     <i class="message-list-icon icon-voice-mail custom-icon"></i> 
     <span class="sender" data-phone="withheld" title="Identity withheld">Identity withheld (withheld)</span> 
     <span class="time" title="Mar 22, 2016 09:59 PM">Mar 22, 2016 09:59 PM</span> 
     <span class="summary"> 
     <span class="text"> Voicemail (4 sec) </span> 
     </span> 
     </span> 
     </div> 
     <div class="list-item filterable message-item js-message-item cp " data-id="7191"> 
     <span class="inline"> 
     <input class="custom js-message-item-checkbox" type="checkbox"> 
     <label></label> 
     </span> 
     <span class=" " data-id="7191"> 
     <i class="message-list-icon icon-voice-mail custom-icon"></i> 
     <span class="sender" data-phone="withheld" title="Identity withheld">Identity withheld (withheld)</span> 
     <span class="time" title="Mar 04, 2016 04:53 AM">Mar 04, 2016 04:53 AM</span> 
     <span class="summary"> 
     <span class="text"> Voicemail (4 sec) </span> 
     </span> 
     </span> 
     </div> 
     <div class="list-item filterable message-item message-unread js-message-item cp " data-id="7074"> 
     <span class="inline"> 
     <input class="custom js-message-item-checkbox" type="checkbox"> 
     <label></label> 
     </span> 
     <span class=" " data-id="7074"> 
     <i class="message-list-icon icon-voice-mail custom-icon"></i> 
     <span class="sender" data-phone="5555551756" title="cert 1756">cert 1756 (555.555.1756)</span> 
     <span class="time" title="Mar 03, 2016 09:03 AM">Mar 03, 2016 09:03 AM</span> 
     <span class="summary"> 
     <span class="text"> Voicemail (4 sec) </span> 
     </span> 
     </span> 
     </div> 

答えて

1

あなたはDataTableとDataViewを使用する必要があると思います。最初のステップ:すべての行をセルごとにDataTableに追加します。次に、DataViewを作成し、フィールドで並べ替えます。並べ替えをクリックし、新しいDataTableインスタンスを作成し、すべての行/セルを再度追加します。最後に、DataViewとDataTableの各行のデータを比較します。 下記のコードを参照してください:

public void TestSorting() 
{ 
    DataTable table1 = GenerateTable(); 
    DataView dv = table1.DefaultView; 
    dv.Sort = "datetime ASC"; // or "datetime DESC" 
    DataRowCollection sortedRows = dv.ToTable().Rows; 

    // Click sort here e.g. timeHeader.Click(); 

    DataTable table2 = GenerateTable(); 
    DataRowCollection rows = table1.Rows; 

    // Compare sortedRows and rows here 
} 

public DataTable GenerateTable() 
{ 
    DataTable table = new DataTable(); 
    table.Columns.Add("datetime", typeof(DateTime)); 
    table.Columns.Add("sender", typeof(string)); 
    table.Columns.Add("time", typeof(string)); 
    table.Columns.Add("summary", typeof(string)); 

    IReadOnlyCollection<IWebElement> rows = driver.FindElements(By.CssSelector("#message-list > div.list-item ")); 
    foreach (var listItem in rows) 
    { 
     IWebElement sender = listItem.FindElement(By.CssSelector("span.sender")); 
     IWebElement time = listItem.FindElement(By.CssSelector("span.time")); 
     IWebElement summary = listItem.FindElement(By.CssSelector("span.summary")); 

     DataRow r = table.NewRow(); 

     string format = "MMM dd, yyyy hh:mm tt"; 
     DateTime dt = DateTime.ParseExact(time.Text.Trim(), format, CultureInfo.InvariantCulture); 
     r["datetime"] = dt; 
     r["sender"] = sender.Text; 
     r["time"] = time.Text; 
     r["summary"] = summary.Text; 

     table.Rows.Add(r); 
    } 

    return table; 
} 
+0

ありがとうございました。私は今夜​​、私が家に帰るときこれを見ていきます。私は数分間それを再生し、私はわずか3行を持っていますが、sortedRowsと行はカウントで113を返しています、それはアイテム配列の重複のように見えます、なぜ私は分かりません。行と並べ替えられた行でAreEqualを実行するのが失敗しています。ヘルプの感謝。私は以前このプロセスを見たことがないし、間違いなくかなりクールです。 – Dazed

+0

@Dazed完全なHTMLソースを投稿できますか?だから私は何が行のロケータでなければならないか把握することができます。 – Buaban

+0

私は今夜家に帰るときに私はそれを追加します。助けてくれてありがとう。 – Dazed

関連する問題