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.

3

There are 3 best solutions below

3
On BEST ANSWER

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.

2
On

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.

5
On

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