

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to select the Date Picker In Selenium WebDriver?
We can select the date picker in Selenium. It is slightly difficult to handle calendar controls as the day, month and year selection can be represented via different UI.
Sometimes they are represented by the dropdown or by forward and backward controls. Let us select the date picker as shown below.
From Date −
To Date −
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.support.ui.Select; public class DatePicker{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String frdate = "20"; String todate = "26"; driver.get("https://jqueryui.com/datepicker/#date−range"); // wait of 4 seconds driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); // maximize browser driver.manage().window().maximize(); // identify frame and switch to it WebElement e = driver.findElement(By.xpath("//*[@id='content']/iframe")); driver.switchTo().frame(e); // choose from date driver.findElement(By.xpath("//input[@id='from']")).click(); Thread.sleep(1000); // choose month from dropdown WebElement m = driver .findElement(By.xpath("//div/select[@class='ui− datepicker−month']")); Select s = new Select(m); s.selectByVisibleText("Jan"); Thread.sleep(1000); // select day driver.findElement(By.xpath("//td[not(contains(@class,'ui−datepicker− month'))]/a[text()='"+frdate+"']")).click(); Thread.sleep(1000); // choose to date driver.findElement(By.xpath("//input[@id='to']")).click(); Thread.sleep(1000); // choose month from dropdown WebElement n = driver .findElement(By.xpath("//div/select[@class='ui− datepicker−month']")); Select sel = new Select(n); sel.selectByVisibleText("Feb"); Thread.sleep(1000); // select day driver.findElement(By.xpath("//td[not(contains(@class,'ui−datepicker− month'))]/a[text()='"+todate+"']")).click(); Thread.sleep(1000); } }
Output
- Related Questions & Answers
- How to Select date from a datepicker with Selenium Webdriver using Python?
- How can I select date from a datepicker div using Selenium Webdriver?
- How to select checkboxes using selenium java webdriver?
- How to Select Value from DropDown using Selenium Webdriver?
- How to use date time picker in Android?
- How to create a date picker using JavaFX?
- Style options for the HTML5 Date picker
- How to display date and time picker in ReactNative?
- Handling DropDown And Multiple Select in Webdriver using Selenium
- How does the Selenium WebDriver work?
- How to use Date Time Picker Dialog in Kotlin Android?
- Create a Date Picker Calendar in Tkinter
- How do I create a date picker in tkinter?
- The Architecture of Selenium WebDriver.
- Selenium RC vs Selenium webdriver.
Advertisements