I want to select a particular date using JavaScript executor but am not able to select and I also didn't get any execution.
WebDriver driver = new FirefoxDriver();
driver.get("http://spicejet.com/");
String date ="11/03";
WebElement element = driver.findElement(By.xpath("//input[@id='ctl00_mainContent_view_date1']"));
element.click();
DatePicker(driver,element,date);
public static void DatePicker(WebDriver driver, WebElement element, String date)
{
JavascriptExecutor js = ((JavascriptExecutor) driver);
js.executeScript("arguments[0].setAttribute('value'," + date + ");" , element);
}
In inspect element I get this
<td class="ui-datepicker-week-end ui-datepicker-current-day"
data-year="2018"
data-month="3"
data-event="click"
data-handler="selectDay">
<a class="ui-state-default ui-state-active" href="#">15</a>
</td>
Try to get all the elements that are inside the "td" tag and place it inside a List . Then make a FOR looking for the day you want to select and click on it. Here is the code I use to solve this type of problem.
WebElement dateWidget = driver.findElement("ui-datepicker-div");
List<WebElement> columns = dateWidget.findElements(By.tagName("td"));
for (WebElement cell : columns) {
if (cell.getText().equals(day)) {
cell.findElement(By.linkText(day)).click();
}
}
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.