I am trying to pick a date on a date picker field and I want to be able to do this by firing javascript on selenium webdriver. I tried the below, which works by being able to go to the date window, however I thought there should be a way to just fire a javascript in @driver.execute_script(). Any javascript experts to help here please?
require 'selenium-webdriver'
@browser = Selenium::WebDriver.for :chrome
@browser.navigate.to 'http://adam.goucher.ca/parkcalc/'
@browser.find_element(:xpath => "//img[@alt='Pick a date']").click
#collect all window handles
window_handles = @browser.window_handles.length
# printing the window ids
@browser.window_handles.map do |window|
p window
end
@browser.switch_to.window(@browser.window_handles.last)
@browser.find_element(:link => '4')
#sleep to watch that indeed the date is picked
sleep 5
@browser.quit