只读文本字段
我的网站中有一个只读文本字段。我需要使用黄瓜和 watir 输入日期。但我无法设置任何值。即使使用 value =
方法传递日期值,我也无法输入任何输出。有一个 JavaScript 日历。
我写道:
browser.text_field(:name => "deal[start_date]").value = 'test'
它显示以下错误:
Watir::Exception::ObjectReadOnlyException: Watir::Exception::ObjectReadOnlyException
from /var/lib/gems/1.8/gems/watir-webdriver-0.1.7/lib/watir-webdriver/elements/element.rb:252:in `assert_writable'
from /var/lib/gems/1.8/gems/watir-webdriver-0.1.7/lib/watir-webdriver/elements/text_field.rb:24:in `value='
from (irb):10
请帮助我,我遇到了麻烦。
I have an read-only text-field in my site. And I need to enter a date using cucumber and watir. But I can't set any value. Even passing the value of date with value =
method I can't input any output. There is a JavaScript calendar.
I wrote:
browser.text_field(:name => "deal[start_date]").value = 'test'
it shows the following error:
Watir::Exception::ObjectReadOnlyException: Watir::Exception::ObjectReadOnlyException
from /var/lib/gems/1.8/gems/watir-webdriver-0.1.7/lib/watir-webdriver/elements/element.rb:252:in `assert_writable'
from /var/lib/gems/1.8/gems/watir-webdriver-0.1.7/lib/watir-webdriver/elements/text_field.rb:24:in `value='
from (irb):10
Please help me, I am in a trouble.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这与 xboxer21 指出的一致。我发现这段代码在一个具有类似日历小部件的网站上对我有用。
假设您有一个 HTML 表单,其输入文本字段设置为只读:
在 Ruby Watir 脚本中使用类似 '@ie.text(:name, "FromDate").set("3/23/2011")' 的代码会导致 Ruby 中出现错误,指出该字段是只读的。但使用 eval() 方法可能允许您使用 Javascript 在幕后设置只读字段。
This goes along with what xboxer21 noted. I found this code worked for me on a site that had a similar calendar widget.
Lets say you have an HTML form with input text fields that are set to readonly:
Using code like '@ie.text(:name, "FromDate").set("3/23/2011")' in your Ruby Watir script would result in an error in Ruby stating the field was read-only. But using the eval() method may allow you to use Javascript to set the read-only fields behind the scenes.
好吧,正如错误消息所述,文本字段是只读的。这意味着它无法更改。如果没有 Watir,您将如何更改文本字段的值?您能提供该页面的链接或相关 HTML 吗?
Well, the text field is read only, as the error message says. That means it can not be changed. How would you change the value of the text field without Watir? Can you provide link to the page or relevant HTML?
这就是我在只读文本字段中输入日期的方法,使用的 JS 日历脚本是 http: //www.dynarch.com/projects/calendar/
日期字段旁边有一个小图标,单击它会显示日历小部件。
如果您想选择未来日期或先前日期
这仅使用 IE 进行了测试。
This is what I did to enter a date in a read only text field, The JS calendar script used was http://www.dynarch.com/projects/calendar/
There is a small icon next to the date field which displays the calendar widget upon clicking it.
If you want to select a future date or previous date
This has been tested using IE only.
尝试执行 JavaScript 本身。
Try executing the JavaScript itself.