【问题标题】:How to select year and month from the datepicker-Selenium Webdriver如何从 datepicker-Selenium Webdriver 中选择年份和月份
【发布时间】:2013-12-11 03:30:02
【问题描述】:

我试图从下拉列表中选择 YearMonth,但它是 datepicker 的形式。我无法按 ID 定位,而是按类选择值。请任何人都可以使用 javascript 执行器在 java 中给我示例代码。

这是我的html标签:

<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>

【问题讨论】:

  • 请分享您尝试选择的 html 的来源
  • 任何人请给我一些解决方案
  • 您尝试过使用Select() 类吗?类似WebElement datePicker = Select(driver.findElement(By.className("ui-datepicker-year")); datePicker.selectByVisibleText("2010");

标签: java javascript jquery selenium datepicker


【解决方案1】:

1.要查找元素属性,您可以使用其父元素的 xpath 引用,在您的情况下,您可以使用 id="ui-monthpicker-div" 或类似的,您可以随意使用

2.对于使用其值选择下拉菜单,您可以使用以下类似代码

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

如果有帮助请告诉我:)

【讨论】:

  • 如果添加上面的代码正在获取 webdriver 无法在 new Select(webdriver 行中解决
【解决方案2】:

试试这个,

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

  1. 用作触发器的图标;
  2. 点击图标时显示日历;
  3. 上一年按钮(
  4. 明年按钮(>>),可选;
  5. 上个月按钮(
  6. 下个月按钮(>);
  7. 日期按钮;
  8. 工作日指标;
  9. 日历标题,即“2011 年 9 月”,代表当前月份和当前年份。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 2018-07-05
    • 2011-11-23
    • 2018-03-31
    • 2011-03-21
    • 1970-01-01
    相关资源
    最近更新 更多