Watir: element_by_xpath 的使用

b =Watir::IE.new
b.goto'http://www.google.com/'
txt =b.element_by_xpath("//*[@name='q']")
txt.value= 'Richard Lawrence'
btn =b.element_by_xpath("//*[@name='btnG']")
btn.click

@b.elements_by_xpath("//div[@class='UserServiceValues']").each do |elem|
puts elem.innerText
end
 
defelement_count(element_type, attribute, value)
   return$ie.elements_by_xpath("//#{element_type}[@#{attribute}='#{value}']").length
end
puts element_count("div","class", "font10px titleColumn")

 

posted @ 2013-08-16 16:32  chenpassion  阅读(463)  评论(0编辑  收藏  举报