ace*_*reg 14 automation capybara
我正在编写一个用Capybara填充文本字段的脚本,但在填写字段之前,我想确保字段为空并且文本未自动填充.基本上,我正在寻找相反的
(Object) fill_in(locator, options = {}) #empty_content_of? delete?
Run Code Online (Sandbox Code Playgroud)
在这里找到:http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions.建议吗?
ace*_*reg 14
在与此斗争之后,我问了一位同事,解决方案是使用以下内容:
fill_in(locator, with: "")
Run Code Online (Sandbox Code Playgroud)
所以,例如:
fill_in "Name", with: ""
Run Code Online (Sandbox Code Playgroud)
这很有道理,对许多人来说可能是直观的,但我很难过,无法在SO上找到答案所以我想我会发布它以防万一它可以帮助任何人.
小智 9
您可以使用本机selenium绑定来清除输入字段而无需填充空字符串
element = find('locator')
element.native.clear
Run Code Online (Sandbox Code Playgroud)
我更喜欢这个选项而不是fill_in.
另外,如果你考虑它,填写是限于通过标签或名称找到你的定位器,所以如果它没有标签或名称,你仍然必须使用 find
一个适合我并且始终可靠的解决方案:
field = find('locator')
field.value.length.times { field.send_keys [:backspace] }
Run Code Online (Sandbox Code Playgroud)
从水豚模仿用户行为的角度来看,这对我来说似乎也是一种正确的方法。
对我来说,只有这种解决方案有效:
fill_in('Foo', with: 'bar', fill_options: { clear: :backspace })
Run Code Online (Sandbox Code Playgroud)
我在前端有Vue.js。
对于 React,您必须做的远不止这些。fill_in field, with: ''确实native.clear。这在 React 中表现不佳。没有fill_in field, with: 'some text'。因为它是arguments[0].value = ''在输入文本之前执行的。
我遇到了react-datetime. 我已经解决的是:
def fill_in_react_datetime n, options
with = options[:with] == '' ? '' : format_date(options[:with])
fill_in n, with: with, fill_options: {clear: [[:control, 'a'], :delete]}
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9431 次 |
| 最近记录: |