これまで実行したことがあります。コレクションの要素を処理するのはちょっとした苦労です。私の場合は、テーブルを解析し、列のセルに含まれる値をチェックしようとしています。ここ はコードです:テストは、このエラーで失敗 "row.cells [cell_index] .text.should == some_value" 行でWatirはコレクションから要素を見つけることができません
def check_cells_values(table, cell_index)
table.rows.each do |row|
row.cells[cell_index].text.should == some_value
end
end
:
Watir::Exception::UnknownObjectException: unable to locate element, using {:element=>#<Selenium::WebDriver::Element:0x7b40a27fd80f640e id="{af57e857-69ed-5345-a4ae-5ab80dff364a}">}
それは単にに十分です行を繰り返し、各行からテキストを出力します。いくつかの行の後(ランダムに)、同じメッセージで失敗します。
ジャスティンがこの問題を扱っているこのリンクが見つかりましたが、要素のコレクションに結びついたものはどこにも見つかりませんでした。
更新: ここでは、解析している1つのテーブルの行の例を示します。
<tr class="dataRow even first" onclick="highlightElem(this)" onmouseover="if (window.hiOn){hiOn(this);} " onmouseout="if (window.hiOff){hiOff(this);} " onblur="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}">
<td class="dataCell " id="someid3" colspan="1"><a href="/url">8882</a></td>
<td class="dataCell " id="someid2" colspan="1">
<label>Some kind of service</label></td>
<td class="dataCell " id="someid6" colspan="1"></td><td class="dataCell " id="someid7" colspan="1"><input class="btn" id="someid8" onclick="A4J.AJAX.Submit('pgToolOffer:pgForm',event,{'similarityGroupingId':'someid8','oncomplete':function(request,event,data){UpdatePopupPosition();},'parameters':{'selectedRatePlan':'Annual','selectedOfferFriendlyName':'Some service 50$','someid8':'someid8','selectedProduct':'Service Descrition','selectedOfferCode':'product\duration\x2DDG275'} });return false;" value="Show Offer Details" type="button"></td>
</tr>
あなたはそのコードのために得ている例外ですか?私は、 ''に対して未定義のメソッド 'each'があると期待します。つまり 'cells [given_index] .each'は有効ではありません。特定のセル、 'cells [given_index]'があると、繰り返し処理するものはありません。 –
私はジャスティンと契約しています。 '.cells'はコレクションを返しますが、' .cells {index} 'は1つのセルになりますので、繰り返しは何もしません。 rows.ecell内のコードについては、 'row.cell(:index => given_index).text.should == expected_value'のようなものがあります。 –
ごめんなさい、私は間違ったコード。私は必要な修正を加えました。しかし、1つの質問。 'row.cell(:index => given_index).text'は' row.cells [index] 'と同じです(' index'はコレクション内のセルの位置です)? –