`
lihbobo
  • 浏览: 64885 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Web_driver 处理下拉列表选择

阅读更多
类似于新浪微博登陆这种输入框可以从下拉列表中选择匹配的输入名,由于生成的<li>的ID是不固定的,所以很难定位去选择,再加上Web-driver 本身不支持index,所以唯一的选择就是Xpath定位元素,代码比较简单:
dr.navigate.to "http://weibo.com/"

m = dr.find_element(:id => 'loginname')
m.send_keys "xxxxx@163.co" 
m = dr.find_element(:xpath => "//ul[@id='sinaNote']/li[3]")
m.click


顺便说一句,selenium2.0以web-driver驱动的脚本,Ruby版本的语法越来越接近Watir,但方便程度却远远不如Watir,国内鼓吹Selenium的人,是否应该多关注Watir,目前watir在多浏览器支持,分布式方面已经有了长足发展。
附上Web-driver的Ruby版教程:http://blog.csdn.net/nbkhic/article/category/840104
http://www.cnblogs.com/bluescorpio/archive/2012/05/13/2498211.html

Steps to install Selenium - Webdriver : Refer - https://github.com/oneclick/rubyinstaller/wiki/development-kit (Get Download files)

1) Install Ruby - Download and install rubyinstaller-1.9.2-p180.exe.
2) Extract DevKit - Download and extract DevKit-tdm-32-4.5.1-20101214-1400-sfx.exe to a folder you like.
3) Install DevKit - Goto the root folder where you extracted DevKit and execute the commands: ruby dk.rb init & ruby dk.rb install
4) Install the required gems
5) Start with your Webdriver setup.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics