【问题标题】:How to select date from date picker ion selenium web driver?如何从 selenium webdriver 中的 datepicker 中选择日期?
【发布时间】:2014-08-13 12:43:26
【问题描述】:

从 selenium web 驱动程序中的日期选择器中选择日期的代码是什么? 我们在 java selenium web 驱动程序编码上尝试了很多

![Web 驱动程序的 Selenium 编码] [http://i.stack.imgur.com/15gdR.png]

找到下面附加的屏幕截图

【问题讨论】:

  • 我们可能需要查看页面来提供帮助,不像在移动设备上说网站上的日期纠察队是自定义的东西,没有标准可以选择它们。

标签: java testing selenium automation webdriver


【解决方案1】:

试试这个

点击加入日期字段,然后点击所需日期,如

driver.findElement(By.<Joining Date field>).click();
driver.findElement(By.linkText(<Date>)).click();

例如:

driver.findElement(By.id("calendarSelect")).click();
driver.findElement(By.linkText("6")).click();

【讨论】:

  • 以上代码对我不起作用... Inspecting Element 中不存在这样的链接文本
  • 你能告诉我们,HTML 显示的是什么(或)给我们一个日历的链接
【解决方案2】:

使用绝对xpath,只需使用firebug识别该日期选择器的日期并右键单击以获取xpath,并使用该xpath选择该元素

【讨论】:

  • 使用绝对自动生成的 xpath 没有任何优势,而且会使代码变得脆弱。在这种情况下,这是最简单但不正确的解决方案。
【解决方案3】:

试试这个,它永远不会失败

`试试{

    WebElement dateWidget = driver.findElement(By.xpath(OR.getProperty(object)));

    List<WebElement> rows = dateWidget.findElements(By.tagName("tr"));  
    List<WebElement> columns = dateWidget.findElements(By.tagName("td"));  

    for (WebElement cell: columns){
        if (cell.getText().equals(data)){
            cell.findElement(By.linkText(data)).click();
            break; 
        }
    }
}catch(Exception e){
    return Constants.KEYWORD_FAIL+" -- Not able to select the date"+e.getMessage();
}`

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    相关资源
    最近更新 更多