【问题标题】:How to select a date from bootstrap calendar which is read only in selenium webdriver using java?如何从使用java的selenium webdriver中只读的引导日历中选择一个日期?
【发布时间】:2018-03-22 14:31:49
【问题描述】:

这是我们在应用程序中使用的日历,这个字段是只读的,我必须自动选择日期,我无法检查日历,因为当我们点击日历时代码会自动消失,因为我无法在 selenium 中编写代码

【问题讨论】:

标签: java selenium selenium-webdriver


【解决方案1】:

DatePicker 不是 Select 元素。

日期选择器实际上是带有一组行和列的表格。要选择一个日期,您只需导航到我们想要的日期所在的单元格。

所以你的代码应该是这样的:

WebElement we = driver.findElement(your locator);
List<WebElement> columns=we.findElements(By.tagName("td"));

for (WebElement cell: columns){
   //Select 13th Date 
   if (cell.getText().equals("13")){
      cell.findElement(By.linkText("13")).click();
      break;
 }

【讨论】:

    【解决方案2】:

    试试下面的代码,如果它对你有用,请告诉我

     WebElement dateWidget = driver.findElement(By.xpath("Your locator"));
        List<WebElement> columns=dateWidget.findElements(By.tagName("td"));
    
        for (WebElement cell: columns){
           //Select 13th Date 
           if (cell.getText().equals("13")){
              cell.findElement(By.linkText("13")).click();
              break;
         }
    

    【讨论】:

      猜你喜欢
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 2018-01-17
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2019-03-22
      相关资源
      最近更新 更多