How to select the Date Picker In Selenium WebDriver

后端 未结 8 1839
再見小時候
再見小時候 2020-12-03 00:02

Currently working on Selenium WebDriver and using Java. I want to select values in date range from the drop down.. I want to k

8条回答
  •  萌比男神i
    2020-12-03 00:47

    I think this could be done in a much simpler way:

    1. Find the locator for the Month (use Firebug/Firepath)
    2. This is probably a Select element, use Selenium to select Month
    3. Do the same for Year
    4. Click by linkText "31" or whatever date you want to click

    So code would look something like this:

    WebElement month = driver.findElement(month combo locator);
    Select monthCombo = new Select(month);
    monthCombo.selectByVisibleText("March");
    
    WebElement year = driver.findElement(year combo locator);
    Select yearCombo = new Select(year);
    yearCombo.selectByVisibleText("2015");
    
    driver.click(By.linkText("31"));
    

    This won't work if the date picker dropdowns are not Select, but most of the ones I've seen are individual elements (select, links, etc.)

提交回复
热议问题