獲得TD的文本我有休耕代碼:廣東話通過指數
<table id="table1" class="class1">
<thead>...<thead>
<tbody>
<tr id="1">
<td class>cell1</td>
<td class>cell2</td>
<td class>cell3</td>
<td class>cell4</td>
</tr>
<tr id="2">
....
<\tr>
...
我需要去了所有的行,並檢查電池3號有「小區3」爲文本。 (對於初學者) 再經過香港專業教育學院發現,我需要繼續檢查該行的細胞數量不同的字符串3
我已經試過:
string="cell3"
rows=browser.table.rows
rows.each {|tr|
if tr.td(:index =>2).text ==string
puts " Found #{string}"
string="cellK"
end
}
Im做它在一個循環中,因爲有我需要找到幾個字符串。
但即時得到休耕錯誤:
unable to locate element, using {:index=>2, :tag_name=>"td"}
有什麼建議? 如何獲取td的文本? 以及爲什麼我不能通過索引找到td?
你確定每行有相同數量的tds(即'''tr.td(index:2).exists?'''總是返回true。我剛剛在本地嘗試過你的代碼,它工作正常見https://gist.github.com/4369348 – p0deje