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")
原文地址:https://www.cnblogs.com/autotest/p/3262451.html