【发布时间】:2016-03-10 16:22:40
【问题描述】:
require 'rubygems'
require 'watir-webdriver'
require 'watir'
require 'rspec'
require 'cucumber'
require 'selenium-webdriver'
我收到以下错误,想知道如何构造正确的(参见下面的错误)Watir 语法来处理我的正则表达式以在文件中设置文本。该元素是动态的。正则表达式只是删除四位数字并保持 id 的一致部分(见下文)。顺便说一句,由于元素 ID 本身是动态的,xpath 或 css 选择方法都不起作用。
Unable to locate element
黄瓜水(步骤)
browser.text_field(:id => '(id=numberfield-)\d\d\d\d(-inputEl').double_click # set '10'
并在 refresh 时更改。见下面的html
HTML:
<input id="numberfield-2840-inputEl" data-ref="inputEl" type="text" role="spinbutton" size="1" name="Quantity" class="x-form-field x-form-text x-form-text-default " autocomplete="off" componentid="numberfield-2840">
【问题讨论】:
-
你是
double_click'ingtext_field?你的正则表达式定位器不应该更像text_field(:id => /numberfield-\d\d\d\d-inputEl/)吗? -
为了扩展@orde 所说的内容,您传递的是字符串(即完全匹配的文本)而不是正则表达式(即模式或部分匹配)。
-
双击只是为了看看它是否到达那么远并单击了该字段,感谢您的反馈。认为我可以解决问题。