水豚的 fill_in 方法未按预期工作
我的页面中有 2 个表格。第一个表单有一个字段“用户名”,第二个表单有一个字段“用户名:”。
当 fill_in 标签时,:with => value
运行(其中 label = "Username:"),标记为“Username”的输入框被填充。
我将“用户名:”更改为“用户名:”,但即使如此,“用户名”也会被填充。
我做错了什么?
I have 2 forms in my page. The first form has a field "Username" and the second form has a field "Username:".
When fill_in label, :with => value
is run (where label = "Username:"), the input box labeled "Username" is getting filled instead.
I changed "Username:" to "User name:" but even then "Username" gets filled.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,您的页面上有 2 个不同表单上有 2 个相同名称的文本输入。
我相信
fill_in some_field
会查找名称或 ID 与some_field
匹配的输入,而不是读取附加的标签。 编辑:它实际上会寻找附加标签 - 感谢 AlistairH 的更正我建议获得您想要的行为的最佳方法是使用
within
块:替换'form1' 以及包含您要定位的文本框的表单的名称。
我认为这比依赖空格或冒号的存在来区分页面上几乎相同的命名元素更可靠、更易读
If I understand correctly, you have 2 identically named text inputs on 2 different forms on your page.
I believe
fill_in some_field
will look for an input with a name or ID matchingsome_field
, rather than reading an attached label. Edit: It does actually look for an attached label - thanks to AlistairH for the correctionI would suggest the best way to get the behaviour you want is using a
within
block:Replace 'form1' with the name of whichever form contains the textbox you'd like to target.
I would consider this to be far more reliable, and readable, than relying on the presence of spaces or colons to differentiate between almost identically named elements on the page