1.watir 测试GUI,在某些情况下,页面元素没有ID或name或其它可以让watir 定位的信息,这时用xpath可以解决这种问题.
2.在安装有watir的情况下,直接安装REXML.(下载REXML后,在命令行下进入bin目录,运行ruby install.rb就行.)
3示例:
html代码:
<html>
<head>
</head>
<body>
<table>
<tr>
<td><img src="1.jpg">First Image</td>
</tr>
</table>
<table>
<tr>
<td><a href="http://www.google.com" target="_blank"><img src="2.jpg">Second Image</td>
</tr>
</table>
<table>
<tr>
<td><img src="3.jpg" onclick="javascript:alert('img 3 click')">Third Image</td>
<td>
</td>
</tr>
</table>
<select foo="bar">
<option value="1">1</option>
<option value="2">2</option>
</select>
<p><a href="http://www.google.com" target="_blank"><span >tips:</span></p>
</body>
</html>
watir代码:
require "watir"
test_site= "G://xpp.html"
ie=Watir::IE.new
ie.goto test_site
ie.cell(:xpath, "//img[@src='1.jpg']/").click()
ie.cell(:xpath,"//select[@foo='bar']").click
ie.cell(:xpath,"//span[contains(text(),'tips:')]").click
ie.element_by_xpath("//span[contains(text(),'tips:')]").click
ie.select_list(:xpath,"//select[@foo='bar']").select("2")
#ie.link(:url,"http://www.google.com").click
#unable to locate object