2014-3-26 00:44| 发布者: tianzc| 查看: 843| 评论: 0
当使用id定位到正确的元素后,highlight方法会将该元素以红色高亮显示,借此也可以验证代码是否工作正常。 使用name属性定位 soso首页的搜索输入框的html代码如下: <input type="text" name="w" smartpid="sb.idx" smartch="sb.c.idx" autocomplete="off" id="s_input" value=""> # 同样定位soso首页的搜索框 s_input = dr.find_element(:name => 'w') 使用css属性定位 soso首页的搜索输入框的html代码如下: <input type="text" name="w" smartpid="sb.idx" smartch="sb.c.idx" autocomplete="off" id="s_input" value=""> 官方文档上说Selenium-WebDriver支持css3语法,这对使用jquery的同学来说无疑是一个好消息。 # css属性定位soso首页搜索框 s_input = dr.find_element(:css => '#s_input') 使用xpath定位 soso首页的搜索输入框的html代码如下: <input type="text" name="w" smartpid="sb.idx" smartch="sb.c.idx" autocomplete="off" id="s_input" value=""> # 使用xpath定位soso首页搜索框 s_input = dr.find_element(:xpath => %Q{//input[@id='s_input' and @name='w']}) 使用其他方式定位 在定位link对象的时候,可以使用link和link_text属性; 另外还可以使用tag_name属性定位任意元素; 定位多个元素 find_elements方法可以定位一组对象,例如
|