[英]how to get src attribute of <img> tag using ruby watir
<table>
<tr>
<td>hello</td>
<td><img src="xyz.png" width="100" height="100"></td>
</tr>
</table>
tabledata.rows.each do |row|
row.cells.each do |cell|
puts cell.text
end
end
puts "end"
得到輸出 - >
hello
end
我應該怎么做這樣的輸出 - >
hello
xyz.png
end
沒有使用Nokogiri。
獲取屬性
您可以使用Element#attribute_value
方法獲取Element#attribute_value
。 例如,
element.attribute_value('attribute')
對於許多標准屬性,您還可以執行以下操作:
element.attribute
輸出單元格文本或圖像文本
假設單元格有文本或圖像:
這看起來像:
tabledata.rows.each do |row|
row.cells.each do |cell|
if cell.image.exists?
puts cell.image.src #or cell.image.attribute_value('src')
else
puts cell.text
end
end
end
puts "end"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.