简体   繁体   中英

How to select year and month from the datepicker-Selenium Webdriver

Am trying to select Year and Month from the drop down but it is in the form of datepicker. I can't able to target by ID and it's selecting the value by class. Please anyone can give me sample code in java with javascript executor.

Here is my html tag:

<div id="ui-monthpicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" style="position: absolute; top: 413.8px; left: 998.9px; z-index: 1; display: none;">

<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all">

<a class="ui-datepicker-prev ui-corner-all" title="Prev" onclick="MP_jQuery_1386732165275.monthpicker._adjustDate('#fromMonth', -1, 'Y');">

<span class="ui-icon ui-icon-circle-triangle-w">Prev</span>

</a>
<a class="ui-datepicker-next ui-corner-all" title="Prev"      onclick="MP_jQuery_1386732165275.monthpicker._adjustDate('#fromMonth', +1, 'Y');">

<span class="ui-icon ui-icon-circle-triangle-e">Prev</span>
</a>

<div class="ui-datepicker-title">

<select class="ui-datepicker-year" onchange="MP_jQuery_1386732165275.monthpicker._selectYear('#fromMonth', this, 'Y');">

<option value="2010">2010</option>

<option value="2011">2011</option>

<option value="2012">2012</option>

<option selected="selected" value="2013">2013</option>

</select>

</div>

1.For finding the element property you can use xpath reference from its parent elements, in your case you can use id="ui-monthpicker-div" or similar one which u feel free

2.For selecting the drop down using its value you can use following similar code

Select select = new Select(webdriver.findElement(By.xpath("//div[@id='ui-monthpicker-div']//select[1]")); select.selectByValue("2010");

Please let me know if it helps :)

try this,

http://seleniumcapsules.blogspot.com/2012/10/design-of-datepicker.html ,

  1. an icon used as a trigger;
  2. display a calendar when the icon is clicked;
  3. Previous Year button(<<), optional;
  4. Next Year Button(>>), optional;
  5. Previous Month button(<);
  6. Next Month button(>);
  7. day buttons;
  8. Weekday indicators;
  9. Calendar title ie "September, 2011" which representing current month and current year.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM