“类型错误:无法将字符串转换为整数”当尝试 CTRL 单击或 SHIFT 单击 watir-webdriver/selenium-webdriver 脚本时

发布于 2024-12-11 07:51:08 字数 3178 浏览 0 评论 0原文

我正在尝试在 Chrome 浏览器上使用 watir-webdriver/selenium-webdriver 在黄瓜脚本中选择定义为表的日期选择器中的多个项目。

日期选择器允许 Ctrl 和 Shift 作为修饰符。

这是单元格代码:

<div type="button" class="datepicker_day" onclick="if(!ample.$instance(this).$isAccessible()) return; DatePicker.onSelectDay(ample.$instance(this), '2011/06/03')" onmouseover="if(!ample.$instance(this).$isAccessible()) return;if (!this.className.match(/_day-disabled/)) this.className += 'datepicker_day-hover'" onmouseout="if(!ample.$instance(this).$isAccessible()) return; if (!this.className.match(/_day-disabled/)) this.className = this.className.replace('datepicker_day-hover', '')">3</div>

这是日期选择器行为的示例 -

http://demo.essentialobjects.com/Demos/ Calendar/Designs/Windows%20(Multi-Month)/Demo.aspx


我尝试使用:

driver.action.key_down(:shift).
click(element).
click(second_element).
perform

但我得到“TypeError:无法将字符串转换为整数”。

from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:59:in `[]'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:59:in `add_backtrace'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:23:in `error'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:50:in `assert_ok'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/http/common.rb:54:in `new'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/http/common.rb:54:in `create_response'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/http/default.rb:64:in `request'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/http/common.rb:35:in `call'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/bridge.rb:430:in `raw_execute'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/bridge.rb:408:in `execute'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/bridge.rb:274:in `sendModifierKeyToActiveElement'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/common/keyboard.rb:26:in `press'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/common/action_builder.rb:122:in `block in perform'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/common/action_builder.rb:121:in `each'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/common/action_builder.rb:121:in `perform'

有人能够在他的代码中使用它吗? 或者有人有向鼠标事件发送修饰符的解决方案吗? 提前致谢。

I am trying to select multiple items in a date picker defined as table, in a cucumber script using watir-webdriver/selenium-webdriver on Chrome browser.

The date picker allows Ctrl and Shift as modifiers.

This is the code for a cell:

<div type="button" class="datepicker_day" onclick="if(!ample.$instance(this).$isAccessible()) return; DatePicker.onSelectDay(ample.$instance(this), '2011/06/03')" onmouseover="if(!ample.$instance(this).$isAccessible()) return;if (!this.className.match(/_day-disabled/)) this.className += 'datepicker_day-hover'" onmouseout="if(!ample.$instance(this).$isAccessible()) return; if (!this.className.match(/_day-disabled/)) this.className = this.className.replace('datepicker_day-hover', '')">3</div>

And this is a sample to what the datepicker is behaving -

http://demo.essentialobjects.com/Demos/Calendar/Designs/Windows%20(Multi-Month)/Demo.aspx

I have tried to use:

driver.action.key_down(:shift).
click(element).
click(second_element).
perform

but I get "TypeError: can't convert String into Integer".

from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:59:in `[]'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:59:in `add_backtrace'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:23:in `error'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:50:in `assert_ok'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/http/common.rb:54:in `new'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/http/common.rb:54:in `create_response'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/http/default.rb:64:in `request'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/http/common.rb:35:in `call'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/bridge.rb:430:in `raw_execute'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/bridge.rb:408:in `execute'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/remote/bridge.rb:274:in `sendModifierKeyToActiveElement'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/common/keyboard.rb:26:in `press'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/common/action_builder.rb:122:in `block in perform'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/common/action_builder.rb:121:in `each'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.9.1/lib/selenium/webdriver/common/action_builder.rb:121:in `perform'

Was anyone able to use this in his code?
Or has anyone a solution for sending modifiers to mouse events?
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往昔成烟 2024-12-18 07:51:08

关于 Watir-Webdriver,我向 Jari(Watir-webdriver 背后的主要驱动力)询问了这个问题,得到了以下答案,如果你非常需要这个,这可能会给你一条追求的道路

watir-webdriver 中还没有暴露任何内容,但您应该
能够使用 WebDriver 中的操作 API 来完成此操作(请参阅
http://rubydoc.info/gems/selenium-webdriver/2.10 .0/Selenium/WebDriver/ActionBuilder)。
我不确定跨浏览器对此的支持程度如何 - 但从
Java 测试(最广泛的)目前看起来是这样
仅在 Firefox + Linux 上受支持:

http://code.google.com/p/selenium/source/browse/trunk/java/client/test/org/openqa/selenium/interactions/CombinedInputActionsTest.java#50< /p>

我还创建了一个功能请求 Github 上的 Watir-Webdriver 项目,如果这是您需要的东西,您可能需要对其进行评论以表明您的需求。

With regard to Watir-Webdriver I asked Jari (the main driving force behind Watir-webdriver) about this and got the following answer, which may give you a path to pursue if you need this badly enough

There's nothing exposed in watir-webdriver (yet), but you should be
able to do it with the actions API in WebDriver (see
http://rubydoc.info/gems/selenium-webdriver/2.10.0/Selenium/WebDriver/ActionBuilder).
I'm not sure how well-supported this is across browsers - but from the
Java tests (which are the most extensive) it looks like it's currently
only supported on Firefox + Linux:

http://code.google.com/p/selenium/source/browse/trunk/java/client/test/org/openqa/selenium/interactions/CombinedInputActionsTest.java#50

I also created a feature-request in the Watir-Webdriver project on Github, if this is something you need, you may want to comment on it to make your needs known.

花开雨落又逢春i 2024-12-18 07:51:08

这将从页面上的第三个日历中选择2009年12月1-6日:

require "watir-webdriver"
browser = Watir::Browser.new
browser.goto "http://www.eyecon.ro/datepicker/"
browser.p(:id => "date3").span(:text => "1").click
browser.p(:id => "date3").span(:text => "6").click

我没有注意到日历响应shift或ctrl(手动)。第一次单击将选择开始日期,第二次单击将选择结束日期。

This will select December 1-6 2009 from the third calendar on the page:

require "watir-webdriver"
browser = Watir::Browser.new
browser.goto "http://www.eyecon.ro/datepicker/"
browser.p(:id => "date3").span(:text => "1").click
browser.p(:id => "date3").span(:text => "6").click

I did not notice that calendar responds to shift or ctrl (manually). The first click will select start date, the second one end date.

谁对谁错谁最难过 2024-12-18 07:51:08

我没有注意到日历响应 Shift 或 Ctrl(手动)。您可以通过单击日期来选择最多 5 天。如果您选择第六个,则您选择的第一个将自动取消选择。

这将选择 2011 年 11 月 1 日和 3 日:

require "watir-webdriver"
browser = Watir::Browser.new
browser.goto "http://nogray.com/calendar.php#tryit"
browser.span(:id => /ng_button_.*_icon/, :index => 1).click # open calendar
browser.td(:id => /11_1_2011/).click
browser.td(:id => /11_3_2011/).click

I did not notice that calendar responds to shift or ctrl (manually). You can select up to 5 days by clicking the day. If you select sixth, the first one that you have selected will automatically be unselected.

This will select November 1 and 3 2011:

require "watir-webdriver"
browser = Watir::Browser.new
browser.goto "http://nogray.com/calendar.php#tryit"
browser.span(:id => /ng_button_.*_icon/, :index => 1).click # open calendar
browser.td(:id => /11_1_2011/).click
browser.td(:id => /11_3_2011/).click
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文