Ruby selenium-client 使用中遇到的问题

本文提供了一个使用 Ruby 和 Selenium 客户端 API 的示例代码,演示了如何启动 IE 浏览器并进行搜索操作。文章还介绍了在遇到权限问题时的解决方法。

 Ruby selenium-client的例子代码

 

#!/usr/bin/env ruby
#
# Sample Ruby script using the Selenium client API
#
require "rubygems"
gem "selenium-client", ">=1.2.18"
require "selenium/client"

begin
  @browser = Selenium::Client::Driver.new \
      :host => "localhost", 
      :port => 4444, 
      :browser => "*iexplore", 
      :url => "http://www.google.com", 
      :timeout_in_second => 1

  @browser.start_new_browser_session
	@browser.open "/"
	@browser.type "q", "Selenium seleniumhq.org"
	@browser.click "btnG", :wait_for => :page
	puts @browser.text?("seleniumhq.org")
ensure
  @browser.close_current_browser_session    
end


这段代码跑起来,一直处于运行等待状态。

所以你要将上面代码中browser 从 *iexplore  改为 *iehta,这个问题便迎刃而解。

如果你遇到下面的问题。解决方法也是一样的。

21:47:43.125 INFO - Got result: 没有权限 on session 706b1057e2dd4791a87b51f48ad2
70ce


 

1. Download the latest version of Selenium RC 2. Unzip the file save it C:\selenium-remote-control-1.0.3 3. command prompt>java -version –> Version should grater than 1.6.0_5 4. command prompt go to –> C:\selenium-remote-control-1.0.3\selenium-server-1.0.3>java -jar selenium-server.jar 5. Download the RubyInstaller– The Ruby Installer is currently available only for the Windows platform. The version that I have downloaded was Ruby 1.9.2-p0 6. Install the RubyInstaller by double slicking on the .exe file. A new Ruby folder is created in your C drive Ruby192 7. Download the selenium-client to c:\Ruby192\bin. The version I have downloaded was selenium-client 1.2.18 8. Set the CLASSPATH C:\Ruby192\bin – This is done by adding System Variables 9. Go to Cmd Prompt –> c:\Ruby192\bin>gem install selenium-client-1.2.18.gem Once you install selenium-client you should get the following conformation message: ' 1 gem installed ' Installing ri documentation for selenium-client-1.2.18… ' Installing RDoc documentation for selenium-client-1.2.18… 10. Open a text editor and wirte your selenium test script code and save the file as googlesearch.rb under your test script folder in this example c:\seleniumrubytest 11. Go to c:\seleniumrubytest where you have the ruby script and execute the command ruby googlesearch.rb. Also make sure that you have the Selenium RC server running. 12. The selenium script will get executed and you will see the results on the command prompt. Loaded suite googlesearch Started . Finished in 11.593750 seconds. 1 tests, 2 assertions, 0 failures, 0 errors, 0 skips Test run options: –seed 23438
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值