类似于新浪微博登陆这种输入框可以从下拉列表中选择匹配的输入名,由于生成的<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.
分享到:
相关推荐
RPi_3_SPI_TPM_Driver_And_Automatic_Driver_Load.patch 英飞凌SPI TPM树梅派驱动
Quectel_LTE&5G_Windows_USB_Driver_V2.2.4
ZTE_Develop_Driver.exe 中兴GD115 GD116相关驱动 LTE 4G ZTE_Develop_Driver.exe 中兴GD115 GD116相关驱动 LTE 4G
DJI_WIN_Driver_Installer
VBCABLE_A_B_Driver_Pack43 官网 有需要的可以下载。
Quectel_EC200T_Linux_USB_Driver_User_Guide_V1.0.pdf
spacedesk_driver_Win_10_64_v1067_BETA_2.msi
HASP_HL_driver_setup.zip
不用解释:Motorola_End_User_Driver_Installation_5.0.0_32bit.msi 摩托罗拉手机驱动 摩托罗拉手机驱动 摩托罗拉手机驱动
spacedesk_driver_Win_10_64_v1065_BETA.msi
Samsung_NVM_Express_Driver_3.3.exe
xdma_driver_win_src_12052020
GosuncnWelink_Driver_Release_1.0.0.7(1).exe
SIMOCODE ES USB驱动程序_SIRIUS_USB_PC_CABLE_DRIVER_V21228
Motorola_End_User_Driver_Installation_6.4.0_64bit的资源
FreeMASTER_Serial_Communication_Driver_V2_0
Register to get VBCABLE_A_B_Driver_Pack43.zip
SAMSUNG_USB_Driver_for_Mobile_Phones.exe
移远4G通讯模块win系统最新驱动:Quectel_LTE_Windows_USB_Driver_V2.1.6.zip
Linux__driver Linux__driver