Amey Amey - 6 months ago 95
jQuery Question

Selenium click on Bootstrap datepicker does not work when browser is in the back ground

Clicking on the input field

<input id="dp1" class="span2" type="text" value="02-16-2012">


When the browser is in the back ground, does not display the datepicker popup.
Using javasccript or jquery to click the input field does not display the date picker popup either.

driver.find_element_by_css_selector('#dp1').click() # works when the browser window is in the foreground
document.querySelector('#dp1').click() # does not display the date picker popup
$('#dp1').click() # does not display the date picker popup


are the three techniques I used on this page.

I run my tests over the selenium grid and each viewing display can have multiple browsers open at the same time, possibly placing the browser page containing the datepicker element in the background, which results in unreliable tests.

So the primary question is -

How come the selenium webdriver click does not work when the browser is in the background?

And the secondary question is-
How do I get around this limitation?

Note:
Sending keys using Selenium or changing the value directly using jquery/js is not an option as it bypasses the datepicker popup and does not actually test the UI aspect and only the functionality.


driver.find_element_by_css_selector('#dp1').send_keys('02-18-2014')
$('#dp1').val('02-18-2014') # updates the date but without using the datepicker


Using selenium v2.39 and firefox2.26 on mac and firefoxv17 on linux

Answer

So I think you can use this :

 $('#dp1').datepicker("show");

While when using selenium.It will be slightly done in different way.use selenium javascript executor while using above code and then parse the html.You can get better idea via this link.

http://www.mythoughts.co.in/2013/04/selecting-date-from-datepicker-using.html#.Uvr546FdSBs