{"id":4015,"date":"2021-02-18T04:25:22","date_gmt":"2021-02-18T04:25:22","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=4015"},"modified":"2021-02-18T04:32:45","modified_gmt":"2021-02-18T04:32:45","slug":"different-approaches-to-select-date-from-datepicker-using-selenium","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/","title":{"rendered":"Different Approaches to select Date from DatePicker Using Selenium"},"content":{"rendered":"<p>Here we are using different methods to select the date from the DatePicker using selenium java. These all <a href=\"https:\/\/studysection.com\/blog\/5-javascript-array-methods-you-should-know\/\">methods<\/a> are listed below one by one with code.<\/p>\n<ol>\n<li><strong>Sendkeys method:<\/strong> In this method, a particular date is filled in the date\/ calendar field with the sendkeys method.\n<p><strong>Code:<\/strong><\/p>\n<p><code><em>public static void firstApproach() {<br \/>\n \t\/\/ Click on the Calendar field<br \/>\n \tWebElement sendate = driver.findElement(By.xpath(\"\/\/input[@id='interview_date']\"));<br \/>\n \t\/\/ Using send method to sent particular date to the calendar field<br \/>\n \tsendate.sendKeys(\"12-january-2021\");<br \/>\n }<\/em><\/code>\n<\/li>\n<li><strong>Selecting a particular date from DatePicker:<\/strong> In this method, choose a particular date using locators and perform a click action to select.\n<p><strong>Code:<\/strong><\/p>\n<p><code><em>public static void secondApproach() {<br \/>\n    \/\/ Click on the Calendar field<br \/>\n    driver.findElement(By.xpath(\"\/\/input[@id='interview_date']\")).click();<br \/>\n    \/\/ Selecting particular date<br \/>\n    driver.findElement(By.xpath(\"\/\/a[normalize-space()='20']\")).click();<br \/>\n  }<\/em><\/code>\n<\/li>\n<li><strong>Getting a list of dates from the Calendar:<\/strong> In this method, get the list of the dates from the calendar, and iterate dates one by one.\n<p><strong>Code:<\/strong><\/p>\n<p><code><em>public static void thirdApproach() {<br \/>\n    \/\/ Click on the Calendar field<br \/>\n    driver.findElement(By.xpath(\"\/\/input[@id='interview_date']\")).click();<br \/>\n    \/\/ Getting list of the active dates and iterating one by one<br \/>\n    List < WebElement > activedates = driver.findElements(By.xpath(\"\/\/table[@class='ui-datepicker-calendar']\/\/a\"));<br \/>\n    for (WebElement dates: activedates) {<br \/>\n      String date = dates.getText();<br \/>\n      System.out.println(date);<br \/>\n      if (date.equals(\"25\")) {<br \/>\n        dates.click();<br \/>\n        break;<br \/>\n     \t}<br \/>\n    \t}<br \/>\n  }<\/em><\/code>\n<\/li>\n<\/ol>\n<h2>Code with these three approaches:<\/h2>\n<p><code>import java.util.List;<br \/>\nimport org.openqa.selenium.By;<br \/>\nimport org.openqa.selenium.WebDriver;<br \/>\nimport org.openqa.selenium.WebElement;<br \/>\nimport org.openqa.selenium.chrome.ChromeDriver;<br \/>\nimport org.openqa.selenium.chrome.ChromeOptions;<br \/>\npublic class DatePicker {<br \/>\n  public static WebDriver driver;<br \/>\n  \/\/ Open browser<br \/>\n  public static void openBrowser() {<br \/>\n    \/\/ System Property for Chrome Driver<br \/>\n    System.setProperty(\"webdriver.chrome.driver\", \"c:\\\\chromedriver.exe\");<br \/>\n    \/\/ Block notification and maximize the Google Chrome Browser<br \/>\n    ChromeOptions opts = new ChromeOptions();<br \/>\n    opts.addArguments(\"--disable-notifications\");<br \/>\n    opts.addArguments(\"start-maximized\");<br \/>\n    driver = new ChromeDriver(opts);<br \/>\n    \/\/ Delete all cookies<br \/>\n    driver.manage().deleteAllCookies();<br \/>\n    \/\/ Site URL<br \/>\n    driver.get(\"https:\/\/www.studysection.com\/mock-interview\");<br \/>\n  }<br \/>\n  public static void firstApproach() {<br \/>\n    \/\/ Click on the Calendar field<br \/>\n    WebElement sendate = driver.findElement(By.xpath(\"\/\/input[@id='interview_date']\"));<br \/>\n    \/\/ Using send method to send particular date to the date field<br \/>\n    sendate.sendKeys(\"12-january-2021\");<br \/>\n  }<br \/>\n  public static void secondApproach() {<br \/>\n    \/\/ Click on the Calendar field<br \/>\n    driver.findElement(By.xpath(\"\/\/input[@id='interview_date']\")).click();<br \/>\n    \/\/ Selecting particular date<br \/>\n    driver.findElement(By.xpath(\"\/\/a[normalize-space()='20']\")).click();<br \/>\n  }<br \/>\n  public static void thirdApproach() {<br \/>\n    \/\/ Click on the Calendar field<br \/>\n    driver.findElement(By.xpath(\"\/\/input[@id='interview_date']\")).click();<br \/>\n    \/\/ Getting list of the active dates and iterating one by one<br \/>\n    List < WebElement > activedates = driver.findElements(By.xpath(\"\/\/table[@class='ui-datepicker-calendar']\/\/a\"));<br \/>\n    for (WebElement dates: activedates) {<br \/>\n      String date = dates.getText();<br \/>\n      System.out.println(\"Date available for interview: \" + date);<br \/>\n      if (date.equals(\"25\")) {<br \/>\n        dates.click();<br \/>\n        break;<br \/>\n     \t \t}<br \/>\n  \t  }<br \/>\n  }<br \/>\n  public static void main(String[] args) {<br \/>\n    \/\/ call methods one by one<br \/>\n    DatePicker call = new DatePicker();<br \/>\n    call.openBrowser();<br \/>\n    \/\/call.firstApproach();<br \/>\n   \/\/call.secondApproach();<br \/>\n    call.thirdApproach();<br \/>\n    \/\/ Close Browser<br \/>\n    driver.close();<br \/>\n  }<br \/>\n}<\/code><\/p>\n<h3>DatePicker Screenshots:<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/02\/form1.png\" alt=\"Form\"\/><br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/02\/data.png\" alt=\"Data\"\/><\/p>\n<p><small><em>People having good knowledge of Financial accounting can get an <a href=\"https:\/\/www.studysection.com\/financial-accountant-advanced-diploma\">Accounting Certification<\/a> from StudySection to increase their chances of getting a job in this field. You can get a foundation level certification if you are new to Financial accounting or you can go for advanced level certification if you have expert level skills in Financial accounting.<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here we are using different methods to select the date from the DatePicker using selenium java. These all methods are<\/p>\n","protected":false},"author":1,"featured_media":4016,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[628,124],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>StudySection Blog - Different Approaches for DatePicker Using Selenium<\/title>\n<meta name=\"description\" content=\"Here we are using methods to select the date from the datepicker using selenium. These all methods are listed below one by one with code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"StudySection Blog - Different Approaches for DatePicker Using Selenium\" \/>\n<meta property=\"og:description\" content=\"Here we are using methods to select the date from the datepicker using selenium. These all methods are listed below one by one with code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-18T04:25:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-18T04:32:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/02\/datapicker.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Different Approaches to select Date from DatePicker Using Selenium\",\"datePublished\":\"2021-02-18T04:25:22+00:00\",\"dateModified\":\"2021-02-18T04:32:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/\"},\"wordCount\":169,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"DatePicker\",\"selenium\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/\",\"url\":\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/\",\"name\":\"StudySection Blog - Different Approaches for DatePicker Using Selenium\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2021-02-18T04:25:22+00:00\",\"dateModified\":\"2021-02-18T04:32:45+00:00\",\"description\":\"Here we are using methods to select the date from the datepicker using selenium. These all methods are listed below one by one with code.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Different Approaches to select Date from DatePicker Using Selenium\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"StudySection Blog - Different Approaches for DatePicker Using Selenium","description":"Here we are using methods to select the date from the datepicker using selenium. These all methods are listed below one by one with code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/","og_locale":"en_US","og_type":"article","og_title":"StudySection Blog - Different Approaches for DatePicker Using Selenium","og_description":"Here we are using methods to select the date from the datepicker using selenium. These all methods are listed below one by one with code.","og_url":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2021-02-18T04:25:22+00:00","article_modified_time":"2021-02-18T04:32:45+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/02\/datapicker.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Different Approaches to select Date from DatePicker Using Selenium","datePublished":"2021-02-18T04:25:22+00:00","dateModified":"2021-02-18T04:32:45+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/"},"wordCount":169,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["DatePicker","selenium"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/","url":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/","name":"StudySection Blog - Different Approaches for DatePicker Using Selenium","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2021-02-18T04:25:22+00:00","dateModified":"2021-02-18T04:32:45+00:00","description":"Here we are using methods to select the date from the datepicker using selenium. These all methods are listed below one by one with code.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/different-approaches-to-select-date-from-datepicker-using-selenium\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Different Approaches to select Date from DatePicker Using Selenium"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":9712,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4015"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=4015"}],"version-history":[{"count":6,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4015\/revisions"}],"predecessor-version":[{"id":4022,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4015\/revisions\/4022"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/4016"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=4015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=4015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=4015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}