当我读出Watir返回的HTML时,它给了我一个页面,指示我通过我的Mac或PC返回浏览器.似乎我被Watir提供的用户代理重定向.我以为我用Watir驱动浏览器,但似乎并非如此.
ie = Watir::IE.new
ie.goto "http://www.apple.com/safari/download"
ie.checkbox(:name, "21.1.9.12.3.1.3.0").clear
Run Code Online (Sandbox Code Playgroud)
它返回一个UnkownObjectException.与尝试单击"提交"按钮相同.
使用firebug我可以找到复选框,这就是我找到:name的方式.所以我接下来将Watir的HTML输出重定向到一个文件进行检查,
myfile = File.new("safaridebug.html", "w+")
myfile.puts ie.html
myfile.close
Run Code Online (Sandbox Code Playgroud)
通过safaridebug.html查看我注意到我在与Web浏览器不同的页面上.在watir中有什么我可以获得我的网络浏览器中存在的实际HTML,也许是用户代理欺骗?谢谢.
系统规格:运行Win XP SP2的VM,ruby 1.8.7,IE 8
我使用的是firefox,我修改了它的用户代理,使其行为像iphone web浏览器.现在,当我使用watir打开google.com时,现在我想点击searh按钮,这是移动视图中的图像.怎么做.
我想在Watir中重复相同的过程,将(word)作为一个不同的变量,而不在我的.rb文件中再次写出整个代码.所以不必写这个:
website = somewebsite.com
word = someword
browser.goto(website)
if browser.text.include?(word)
puts(website)
end
word = someotherword
browser.goto(website)
if browser.text.include?(word)
puts(website)
end
word = anotherword
browser.goto(website)
if browser.text.include?(word)
puts(website)
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
谢谢.
页面上有2个图像具有相同的图像src链接.如果我使用以下代码,它将单击第一个图像,那么如何单击第二个图像?
browser.image(:src, "https://itc.mzstatic.com/itc/images/btn-grey-small-edit.png").click
Run Code Online (Sandbox Code Playgroud) 我有一个简单的watir(网络驱动程序)脚本进入谷歌.但是,我想使用选项解析器在cmd中设置一个参数来选择一个浏览器.以下是我的脚本:
require 'optparse'
require 'commandline/optionparser'
include CommandLine
require 'watir-webdriver'
describe 'Test google website' do
before :all do
options = {}
opts = OptionParser.new do |opts|
opts.on("--browser N",
"Browser to execute test scripts") do |n|
options[:browser] = n
$b = n.to_s
end
end
opts.parse! ARGV
p options
end
describe 'The test website should be displayed' do
it 'should go to google' do
$ie = Watir::Browser.new($b)
#go to test website
$ie.goto("www.google.com")
end
end
end
Run Code Online (Sandbox Code Playgroud)
执行rspec ietest.rb --browser firefox -f doc只是给了我无效选项,ietest是我文件的名称.任何其他直观的方式通过Web驱动程序设置浏览器,而不改变脚本代码,将是受欢迎的.
我们在页面上有n个具有相同类名的div.
<div class="errors">
</div>
<div class="errors">
Foo is invalid
</div>
Run Code Online (Sandbox Code Playgroud)
我们要做的是检查并查看其中任何带有"错误"类的div是否有消息"Foo无效".
我们可以这样做@ browser.div(:class =>'errors',:index => 2)
但这并不包括消息在第一个或第n个div中的情况.
如果我们可以将所有匹配的div作为数组返回,将其展平,然后执行我们的断言,那将是多么伟大的事情.
或者也许取回匹配的div的数量,以便我们可以迭代它们.
我们正在使用Watir 1.9.2
有没有办法用Watir定位可见元素?
我想只找到可见的表单(通过索引参数),以便Watir返回第一个或第二个可见文本字段.
如何过滤不可见的字段/元素?用xpath可以做到吗?
我一直在犯这样的错误:
puts browser.table(:after? => span(:text => "Asmeniniai duomenys") )[2][2].text
Run Code Online (Sandbox Code Playgroud)
基本上说:
undefined method `span' for main:Object (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
要么
undefined method `table' for main:Object (NoMethodError) etc...
Run Code Online (Sandbox Code Playgroud)
所以我决定找不到桌子.我试过if/else,但这是我第一次使用ruby,我不明白它是否有效.
所以我认为最简单的方法是找出如何突出显示的东西.
任何人都可以建议我如何突出显示元素或如何解决这个问题?
我在Watir webdriver中编写Ruby,我想测试一个CSV文件(我已经读过)的数据的高图精确度.我怎样才能从网站上阅读高清数据?当您将鼠标悬停在点上时,会生成包含许多数据点的高图,数据将显示在一个框中.我无法使用watir webdriver定位元素,因为我从源头看到每个点都是路径标记.我想也许自动光标移动到axy位置但不知道如何做到这一点.有帮助吗?谢谢
我有一个用Ruby编写的使用Selenium,Watir和ChromeDriver的抓取脚本,在Chrome浏览器窗口中都可以正常工作,但是试图以无头模式运行却很成功。
Selenium::WebDriver::Error::UnknownError: unknown error: Element <input id="desired_element" type="checkbox" name="desired_element" checked="checked"> is not clickable at point (660, 594). Other element would receive the click: <html lang="en">...</html>
Run Code Online (Sandbox Code Playgroud)
我正在使用Watir 6.8和最新的Chromedriver 2.33。
任何想法在无头与无头时页面的不同行为背后是什么,我该如何处理?