Mys*_*Man 6 css selenium css-selectors capybara
我正在与水豚一起写硒测试并试图填写一个弹出框.我无法使用capybara中的fill_in方法填写元素的名称.这适用于其他页面中的其他表单,但不适用于此页面.
这是我的测试代码:
describe "Jobs" do
before do
login(users(:admin))
end
it "creates a job on a workspace" do
visit('#/workspaces')
click_button "Create Workspace"
within_modal do
fill_in 'name', :with => "testing-jobs"
click_button "Create Workspace"
end
click_link "Dismiss the workspace quick start guide"
page.should have_content('All Activity')
Workspace.find_by_name("testing-jobs").should_not be_nil
click_link "Jobs"
click_button "Create"
within('#facebox') do
find(".name").click
fill_in '. name', :with => "real job"
choose "onDemand"
click_button "Create"
end
page.should have_content "real job"
end
end
Run Code Online (Sandbox Code Playgroud)
关于工作空间的第一个fill_in工作得很好但是当我到达工作时它只是搞砸了.
这是来自firebug的实际开发代码:
<div id="facebox" class="dialog_facebox" style="top: 30px; left: 424.5px;">
<div class="popup" style="max-height: 626px;">
<div class="content">
<div class="configure_job_dialog dialog">
<div class="dialog_header">
<div class="errors"></div>
<div class="dialog_content" data-template="configure_job_dialog">
<form action="#">
<label class="required">Name</label>
<input class="name" type="text" value="">
Run Code Online (Sandbox Code Playgroud)
我在fill_in方法中使用了name类,但是capybara没有捕获它.我尝试调试一点,看看为什么我的工作区被创建但不是工作.工作区代码如下.
<input type="text" maxlength="256" tabindex="1" placeholder="Name this workspace" name="name">
Run Code Online (Sandbox Code Playgroud)
任何帮助都非常感谢.
问题
根据给出的html,您将无法使用该fill_in方法.原因是:
fill_in方法基于其id属性,名称属性或标签文本来定位元素.它不支持通过CSS选择器定位元素,即.name.fill_in.同样,标签不与输入via for和id属性直接关联.我相信fill_in只检查显式标签(而不是隐式标签).请注意,fill_in工作区的工作原理是因为该输入具有指定的name属性.
解
理想的解决方案是更新输入以具有id属性,name属性或显式标签.但是,如果这不可能或者您需要使用CSS选择器,则可以find使用元素,然后set使用值:
find('.name').set("real job")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4801 次 |
| 最近记录: |