我和Capybara有一些非常奇怪的行为.它固执地拒绝填写我的登录表单的字段.
<fieldset>
<div class="clearfix">
<label for="user_email">E-Mail Adresse</label>
<div class="input">
<input id="user_email" name="user[email]" size="30" type="email" value="">
</div>
</div>
<div class="clearfix">
<label for="user_password">Passwort</label>
<div class="input">
<input id="user_password" name="user[password]" size="30" type="password" value="">
</div>
</div>
<div class="clearfix">
<div class="input">
<input name="user[remember_me]" type="hidden" value="0">
<input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
<label for="user_remember_me">angemeldet bleiben</label>
</div>
</div>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
这里是有趣的开始:
within("#login_form"){ find("#user_email")}
=> #<Capybara::Element tag="input" path="/html/body/div[2]/div[@id='content']/div/div[1]/form[@id='login_form']/fieldset/div[1]/div/input[@id='user_email']">
within("#login_form"){ fill_in("#user_email", with: "foo@example.com")}
Capybara::ElementNotFound: Unable to find field "#user_email"
Run Code Online (Sandbox Code Playgroud)
我不太明白如何才能找到一个元素,但却找不到它.对此的另一双眼睛将不胜感激.
之前我把Chrome二进制文件"chromedriver.exe"放在"C:/ Windows"目录中,Watir从那里选择它.现在我必须将我的项目移动到另一台机器,因此我无法对可执行路径进行硬编码.我还希望二进制文件与Git上的代码保持一致,而不是让每个测试工程师在发布新版本时手动更新二进制文件.
现在我已经将Chrome二进制文件放在绝对路径上了,但是找不到它.这是我试过的(hooks.rb):
Before do
puts "inside hooks in before"
profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = File.join(File.absolute_path('../..', File.dirname(__FILE__)),"browsers/chromedriver.exe")
@browser = Watir::Browser.new :chrome, :profile => profile
end
Run Code Online (Sandbox Code Playgroud)
输出是:
inside hooks in before
Selenium::WebDriver::Error::WebDriverError: Unable to find the chromedriver executable. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at http://code.google.com/p/selenium/wiki/ChromeDriver.
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/chrome/service.rb:21:in `executable_path'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/chrome/service.rb:34:in `default_service'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/chrome/bridge.rb:14:in `initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/common/driver.rb:37:in `new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/common/driver.rb:37:in `for'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver.rb:67:in `for'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/watir-webdriver/browser.rb:46:in `initialize'
C:/Users/Admin/watircukepractice/test_puppies/features/support/hooks.rb:11:in `new'
C:/Users/Admin/watircukepractice/test_puppies/features/support/hooks.rb:11:in `Before'
Run Code Online (Sandbox Code Playgroud)
我在Windows 7上,使用Ruby版本1.9.3p551,我指的是教程http://watirwebdriver.com/chrome/.
如何告诉Watir(和Selenium-WebDriver)chromedriver.exe的位置?
我需要传递javascript中的变量,通过capybara中的excute_script方法执行.
我无法将变量传递给它.
请有人帮帮我.
例:
@idd="sample"
txt=page.execute_script('var user_id = ${@idd}; return user_id;')
puts txt
Run Code Online (Sandbox Code Playgroud)
我期待打印文本示例,但我得到java脚本错误.
我想在我的页面上检查以下代码:
...
<p class="tags-link">
<a href="/search?q=test1" rel="nofollow">test1</a>
<a href="/search?q=test2" rel="nofollow">test2</a>
<a href="/search?q=test3" rel="nofollow">test3</a>
</p>
....
<p class="tags-link">
<a href="/search?q=test4" rel="nofollow">test4</a>
<a href="/search?q=test5" rel="nofollow">test5</a>
<a href="/search?q=test6" rel="nofollow">test6</a>
</p>
Run Code Online (Sandbox Code Playgroud)
....
我使用Watir-webdriver和page-object.我需要通过"tags-link"类获取与块相关的所有链接.
我有以下代码:
element(:tags, :p, :css => "tags-link a")
Run Code Online (Sandbox Code Playgroud)
tags_element仅返回第一个链接.
以下代码将仅提供与第一个块相关的3个链接:
element(:tags, :p, :css => "tags-link")
tags_element.element.links.each do |elm|
puts elm
end
Run Code Online (Sandbox Code Playgroud)
但我需要获得所有标签块
现在我有以下代码可行,但我想成为"页面对象"导向:
@browser.elements(:css =>".tags-link a").each do |tag|
puts tag
end
Run Code Online (Sandbox Code Playgroud)
你可以帮助我...使用页面对象获取与"tags-link"相关的页面上的所有链接
谢谢,安娜
我正在使用 Rails 2.1.0 和 Nokogiri 1.6.1。我想要的似乎很简单。我希望我的 Rails Rest API 返回带有如下元素的 XML:
<PeopleNumber unit="NumberOfPeople">2.235075</PeopleNumber>
Run Code Online (Sandbox Code Playgroud)
我试着写一些类似的东西:
xml = Nokogiri::NML::Builder.new do |xml|
xml.PeopleNumber(:unit => "NumberOfPeople") 2.235075
Run Code Online (Sandbox Code Playgroud)
ActionController 触发语法错误。
如果我尝试将其重写为
xml = Nokogiri::NML::Builder.new do |xml|
xml.PeopleNumber(:unit => "NumberOfPeople") { 2.235075 }
Run Code Online (Sandbox Code Playgroud)
我得到类似的东西
<PeopleNumber unit="NumberOfPeople" />
Run Code Online (Sandbox Code Playgroud)
有谁知道在 Nokogiri 中获得所需行为的方法?
如何在不使用js/jquery的情况下使用watir-webdriver更改href属性值?
我可以得到一个属性值:
@browser.frames[2].div(:id,"mid-2").link(:class,"btn-lrg").attribute_value("href")
Run Code Online (Sandbox Code Playgroud)
但我还需要更改一些href属性值.
当我尝试scroll.to特定元素时,刚得到一个未知错误。例如:
@browser.scroll.to page_element_xy
#=> "Don't know how to scroll to: #< Watir::Div:0x... >! (ArgumentError)"
Run Code Online (Sandbox Code Playgroud)
正常scroll.to :top/ :bottom仍以某种方式工作。
仅仅是DIV问题还是scroll.to功能已总体改变?
在搜索中,我发现以下对我有用的东西:
page_element_xy.scroll.to :center
Run Code Online (Sandbox Code Playgroud)
很高兴知道现在推荐什么。
<div id="divL">
<br><br>
<div id="person">abc</div>
<div id="person">xxx</div>
<div id="person">xxx</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
#divL:first-child div{
background:#ffffff; //doesn't work
}
Run Code Online (Sandbox Code Playgroud)
我想跳过<br>标签并选择第一个div标签(abc)内部divL
第一次下拉:
<select id="MainContent_drpVehicleType" style="width:175px;" name="ctl00$MainContent$drpVehicleType">
<option value="">- SELECT -</option>
<option value="1" title="AUTO">AUTO</option>
<option value="2" title="HD">HD</option>
<option value="3" title="MARINE">MARINE</option>
</select>
Run Code Online (Sandbox Code Playgroud)
第二次下拉:
<select id="MainContent_drpMake" style="width:175px;" name="ctl00$MainContent$drpVehicleType">
<option value="1" title="ACURA">ACURA</option>
<option value="2" title="ALFA ROMEO">ALFA ROMEO</option>
<option value="74" title="ALLIS CHALMERS LIFT TRUCK">ALLIS CHALMERS LIFT TRUCK</option>
<option value="75" title="ALLIS CHALMERS TRACTOR">ALLIS CHALMERS TRACTOR</option>
<option value="4" title="AMERICAN MOTORS">AMERICAN MOTORS</option
</select>
Run Code Online (Sandbox Code Playgroud)
b.select_list(:id, "MainContent_drpVehicleType").select("AUTO")
b.select_list(:id, "MainContent_drpMake").select("ACURA")
Run Code Online (Sandbox Code Playgroud)
并尝试过
`b.select_list(:id, "MainContent_drpMake").wait_until_present.option(:text, 'ACURA')`
Run Code Online (Sandbox Code Playgroud)
**我的问题是从第一次下拉菜单中选择"自动"并且无法从第二次下拉菜单中选择"ACURA"
C:/Ruby193/menu.rb:23:in `<main>':
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.2/lib/watir-webdriver/el
ements/select.rb:218:in `no_value_found': "ACURA" not found in select list (Wati
r::Exception::NoValueFoundException)
from …Run Code Online (Sandbox Code Playgroud)