我有一个选择列表:
<select id="filter">
<option value="Open" selected="selected">Open</option>
<option value="Closed">Closed</option>
</select>
Run Code Online (Sandbox Code Playgroud)
当我选择Closed
页面重新加载时.在这种情况下,它显示已关闭的票证(而不是打开).我手动操作时工作正常.
问题是当我Closed
用Watir选择时页面不会重新加载:
browser.select_list(:id => "filter").select "Closed"
Run Code Online (Sandbox Code Playgroud)
这通常意味着不会触发某些JavaScript事件.我可以用Watir发射事件:
browser.select_list(:id => "filter").fire_event "onclick"
Run Code Online (Sandbox Code Playgroud)
但我需要知道要开火的事件.
有没有办法找出为元素定义了哪些事件?
我有以下代码
browser.link(:text => 'Generate Report').click
browser.radio(:value => 'byTotalValue').wait_until_present(180)
Run Code Online (Sandbox Code Playgroud)
请求生成报告,然后通过在报告页面上查找元素来等待报告.报告最多可能需要2分钟才能显示.
发生的事情是Timeout :: 60秒后从click方法引发错误.我怀疑Watir-Webdriver在click方法中实现了某种形式的等待页面加载,但我没有看到调整值的方法.
任何帮助理解这一点将不胜感激.
使用watir-webdriver调用以下内容时,如何指定打开的浏览器窗口的大小?
browser = Watir::Browser.new(:firefox)
Run Code Online (Sandbox Code Playgroud) 我似乎是一个非常简单和非常需要的方法.我需要从字符串中删除所有非ASCII字符.例如©等.请参阅以下示例.
#coding: utf-8
s = " Hello this a mixed string © that I made."
puts s.encoding
puts s.encode
Run Code Online (Sandbox Code Playgroud)
输出:
UTF-8
Hello this a mixed str
Run Code Online (Sandbox Code Playgroud)
我做的.
当我将其提供给Watir时,会产生以下错误:不兼容的字符编码:UTF-8和ASCII-8BIT
所以我的问题是我想在使用它之前去除所有非ASCII字符.我不知道源字符串"s"使用哪种编码.
我一直在搜索和试验很长一段时间.
如果我尝试使用
puts s.encode('ASCII-8BIT')
Run Code Online (Sandbox Code Playgroud)
它给出了错误:
: "\xC2\xA9" from UTF-8 to ASCII-8BIT (Encoding::UndefinedConversionError)
Run Code Online (Sandbox Code Playgroud) 使用watir-webdriver,如何在点击链接后等待页面加载?
目前我正在做的事情:
sleep n
Run Code Online (Sandbox Code Playgroud)
但这并不理想,因为页面响应变化很大.
是否有方法来测试页面是否准备就绪或页面中是否存在某个元素.我理解在正常的watir gem中有Watir::Waiter.wait_until
或类似的东西,但我在webdriver版本中看不到这一点.
无法找到chromedriver可执行文件.请从http://code.google.com/p/chromedriver/downloads/list下载服务器并将其放在PATH上的某个位置.有关详细信息,请访问http://code.google.com/p/selenium/wiki/ChromeDriver.(硒:: webdriver的::错误:: WebDriverError)
在Ubuntu 13上使用Watir和Ruby.
ruby selenium watir selenium-chromedriver selenium-webdriver
我试图告诉我的watir脚本等待ajax注入的登录框打开.我正在使用watir-webdriver,并在Chrome中进行测试.我无法开始wait_until
工作,如下面(简化)脚本中所评论的那样.
require "rubygems"
require "watir-webdriver"
b = Watir::Browser.new(:chrome)
site = "www.example.com"
b.goto site
puts "Click on Sign In button"
b.link(:id, 'btnLogin').click
puts "Waiting for the username/password dialog to show up"
# Below line does *not* work
# Throws this error: "uninitialized constant Watir::Waiter (NameError)"
Watir::Waiter::wait_until { b.text_field(:id, 'username').exists? }
# Below line does *not* work
# Throws this error: "undefined method `wait_until' for main:Object (NoMethodError)"
wait_until { b.text_field(:id, 'username').exists? }
# Below line *does* work, but I don't …
Run Code Online (Sandbox Code Playgroud) 我想将一个元素拖放到另一个元素的位置,从watir-webdriver脚本中触发.
通过"拖放",我的意思是拿起一个可拖动的元素并将其释放到另一个元素上."可能"是指可以从watir-webdriver脚本执行的任何拖放方法.这包括代码片段,第三方宝石等.
据我所知,拖放是核心watir-webdriver的功能请求(在询问时),所以我(原则上)寻找替代方案.
更新拖放现在是核心watir-webdriver的一部分(从0.5.0开始,我相信)
更新2对于那些寻求启蒙的人来说,这是可能的(从版本0.5.0开始):
a = browser.div(:id => "draggable")
b = browser.div(:id => "droppable")
a.drag_and_drop_on b
Run Code Online (Sandbox Code Playgroud)
和
a = browser.div(:id => "draggable")
a.drag_and_drop_by 100, -200
Run Code Online (Sandbox Code Playgroud) 我想知道watir-webdriver是否能够记录任何控制台错误的输出?这相当于在浏览器中手动打开控制台并在页面加载时查看JS错误.我可以通过watir-webdriver和日志/错误捕获这个吗?
是否可以在Windows上将ruby脚本编译为.exe?我到处搜索过,我尝试了以下内容(看起来像RubyScript2EXE,鞋子和箱子似乎都死了或被遗弃了.):
我在一个干净的系统上使用Windows 7旗舰版(64位)上的Ruby 1.8.7我这样做:
我有一个相当简单的脚本来执行此操作:
require 'rubygems'
require 'watir'
browser = Watir::Browser.new
browser.goto 'http://slashdot.org'
Run Code Online (Sandbox Code Playgroud)
当我运行Ocra时,我没有收到任何错误消息,也没有任何反应:
ocra --output test.exe test.rb
=== Loading script to check dependencies
Run Code Online (Sandbox Code Playgroud)
Exerb似乎是一个更好的解决方案,因为它编译为rbc,它确实做了一些事情:
ruby -r exerb/mkexy test.rb
# Window pops up and after I close it it writes out test.exy
C:\Users\jonathan\dev\Citation>exerb test.exy
C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:146:in `add_file_entry': test.
exy: no such file -- C:/Ruby187/lib/ruby/gems/1.8/gems/win32-api-1.4.8-x86-mingw32/lib/win32/ruby18/win32/api.so (RuntimeError)
from C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:86:in `create_archive'
from C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:85:in `each'
from C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:85:in `create_archive'
from C:/Ruby187/bin/exerb.bat:67:in `main' …
Run Code Online (Sandbox Code Playgroud) watir ×10
ruby ×4
webdriver ×2
compilation ×1
dom-events ×1
events ×1
exe ×1
firewatir ×1
javascript ×1
safariwatir ×1
selenium ×1
web-testing ×1