我很确定watir-webdriver有css选择器支持,但看起来它不再存在了:
$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
$ gem -v
1.8.15
$ gem list selenium-webdriver
*** LOCAL GEMS ***
selenium-webdriver (2.17.0)
$ gem list watir-webdriver
*** LOCAL GEMS ***
watir-webdriver (0.4.1)
$ irb
> require "watir-webdriver"
=> true
> browser = Watir::Browser.new :firefox
=> #<Watir::Browser:0x787eb29124fb7658 url="about:blank" title="">
> browser.goto "google.com"
=> "http://www.google.com.mx/"
> browser.a(:css => "a").flash
Watir::Exception::MissingWayOfFindingObjectException: invalid attribute: :css
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:228:in `assert_valid_as_attribute'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:209:in `normalize_selector'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:191:in `block in normalized_selector'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:188:in `each'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:188:in `normalized_selector' …
Run Code Online (Sandbox Code Playgroud) 我试图让Watir模仿一个移动环境,我从非常有用的http://watirwebdriver.com/mobile-devices/逐字跟踪指示.这是我的代码.
#!/usr/bin/ruby
require 'rubygems'
require 'watir-webdriver'
require "webdriver-user-agent"
require 'headless'
$headmode = 0
$screens = 0
headless = Headless.new if $headmode == 1
headless.start if $headmode == 1
driver = UserAgent.driver(:browser => :firefox, :agent => :iphone, :orientation => :landscape)
....... snip ......
....... snip ......
Run Code Online (Sandbox Code Playgroud)
被抛出的例外是......
/var/lib/gems/1.8/gems/webdriver-user-agent-0.0.5/lib/webdriver-user-agent.rb:39:in `agent_string_for': undefined method `downcase' for :iphone:Symbol (NoMethodError)
from /var/lib/gems/1.8/gems/webdriver-user-agent-0.0.5/lib/webdriver-user-agent.rb:11:in `driver'
from ./test_CAPI.rb:11
Run Code Online (Sandbox Code Playgroud)
不是Ruby开发人员,或者精通WATIR(还),我对这个错误感到困惑.任何人都可以对此有所了解吗?非常感谢Janie
我在Chrome下运行脚本,但在运行脚本时显示错误
要求'watir-webdriver'
b = Watir::Browser.new:chrome
b.goto 'bit.ly/watir-webdriver-demo'
b.text_field(:id => 'entry_0').set 'your name'
b.select_list(:id => 'entry_1').select 'Ruby'
b.select_list(:id => 'entry_1').selected? 'Ruby'
b.button(:name => 'submit').click
b.text.include? 'Thank you'
Run Code Online (Sandbox Code Playgroud)
运行脚本时出现以下错误
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.21.2/lib/selenium/webdr
iver/chrome/service.rb:19:in `executable_path': Unable to find the chromedriver
executable. Please download the server from http://code.google.com/p/chromedrive
r/downloads/list and place it somewhere on your PATH. More info at http://code.g
oogle.com/p/selenium/wiki/ChromeDriver. (Selenium::WebDriver::Error::WebDriverEr
ror)
Run Code Online (Sandbox Code Playgroud) 我使用watir-webdriver并尝试找到元素的位置$browser.div(:id, "foo")
.当我试图点击它时,chromedriver说
元素不可点击(-1707,-799.5)
如何获得元素的坐标?我试过这个:
http://wiki.openqa.org/display/WTR/Right+Click+an+Element
但是当我尝试调用该document()
方法时出现错误.
除非您使用firewatir,否则似乎不是受支持的功能?
我已经浏览了它,似乎无法在任何地方找到它,我遇到了double_click但是在控制台中返回了一个未定义的方法错误.
有谁知道怎么解决这个问题?
在我添加测试的项目中,我有一些复杂的元素“获取”。
我的 textarea 的 html :
<div class="quote">
<div class="clearfix">
<div class="icon"></div>
<div class="text">
<span class="yui3-widget yui3-inputwidget yui3-textareawidget yui3-textareawidget-focused" style="">
<span class="yui3-textareawidget-content">
<textarea name="" placeholder=""></textarea>
</span>
</span>
</div>
<div class="author">
(...) other text_field
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
目前,我使用这一行来设置值
@browser.element(:css => ".quote textarea").send_keys "test"
Run Code Online (Sandbox Code Playgroud)
在 PageObject 中,我应该声明元素并使用它:
# declaration at the top
element(:quote_text, :css => ".quote textarea")
# use it where I need
self.quote_text = "text"
Run Code Online (Sandbox Code Playgroud)
但是当我使用时出现此错误:
undefined method `quote_text=' for #<PublishPage:0x33843c0> (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
我想找到并单击Line Lo
以下值中的值.以下li
有100多条记录具有相同的类名.如何找到Line Lo
并单击该值.
<div id="loc">
<ul id="tab">
<li class="criteria">
<div class="bud">
<div class="inner">
<div class="attr">Code Lo</div>
</div>
</div>
</li>
<li class="criteria">
<div class="bud">
<div class="inner">
<div class="attr">Line Lo</div>
</div>
</div>
</li>
<li class="criteria">
<div class="bud">
<div class="inner">
<div class="attr">Add Lo</div>
</div>
</div>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我试过的时候 browser.ul(id: "tab").li(class: "criteria").div(text: "Line Lo")
得到了失败错误.
Unable to locate element, using(:class => "Criteria", :tag_name=>"li"
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的,不同的属性来找到文本Line Lo
而我失败了.
此外,此元素类似于第45个,因此可以在单击之前向下滚动并刷新此值吗?
提前致谢
我有这个 div:
<div id="loadDIV" class="containerLogo" onclick="ventanaSecundaria('/bienvenido.php',800,600); "></div>
Run Code Online (Sandbox Code Playgroud)
如何使用 watir gem 在 div 内运行 onclick 事件?
class = containerLogo 在浏览器上显示徽标。当您单击该徽标时,您将运行脚本“ventanaSecundaria”,它会打开另一个包含 bienvenido.php 内容的窗口。尝试使用机械化和 nokogiri 宝石无济于事,他们建议尝试 watir gem。
我试图从我尝试过多种组合中单击“先生”,drop down list
但它们似乎都不起作用。
我什至尝试过xpath
这通常是可靠的,但在这种情况下它失败了。
$browser.element(:xpath, "/html/body/div[1]/div[1]/div[1]/div/div[2]/div[1]/div[2]/div/div[2]/div/div[2]/div[2]/form/div[2]/div/div[2]/div/div/div/div/div/ul/li[2]/a").click
Run Code Online (Sandbox Code Playgroud)
我正在使用 Watir 6.16,我遇到了这行代码
<div data-guid="SearchTitle" class="acme"></div>
Run Code Online (Sandbox Code Playgroud)
不知道如何在 Watir 中找到这样的元素,我已经尝试过 -
element(:search_title, custom_attribute: "SearchTitle")
Run Code Online (Sandbox Code Playgroud)
但这没有返回任何内容,所以我被迫使用 xpath 还是还有其他方法?
凯夫
watir ×10
ruby ×7
selenium ×2
automation ×1
css ×1
firewatir ×1
rubygems ×1
testing ×1
user-agent ×1
webdriver ×1