How can I select the drop down date section using selenium?

0 votes
I have just started working on selenium and know only a few things. I was wondering as how can I select an element from the drop down list. I am trying things on facebook's website. The login page has a signup section and there is a dropdown option to fill date of birth how to test that and fill a date?
Dec 18, 2018 in Selenium by Anjali
• 2,900 points
265 views

1 answer to this question.

0 votes

First thing that you need to do is find the ID for the dropdown box you are going to test.

There is a select class used in selenium. 

Here is the eg I used to create the above said scenario:

import org.openqa.selenium.support.ui.Select;

System.setProperty("webdriver.chrome.driver","C:\\Yourpath\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com");
Select year = new Select(driver.findElement(By.id("date")));
year.selectByVisibleText("27");
Select year = new Select(driver.findElement(By.id("month")));
year.selectByVisibleText("Aug");
Select year = new Select(driver.findElement(By.id("year")));
year.selectByVisibleText("2000");
Thread.sleep(5000);

This is not the legit way but agin this also worked so I am just giving this as an option to do things in a simpler way

System.setProperty("webdriver.chrome.driver","C:\\Yourpath\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.id("day")).sendKeys("6");
driver.findElement(By.id("month")).sendKeys("Nov");
driver.findElement(By.id("year")).sendKeys("2000");
Thread.wait(5000);

These were the two ways I know to do this.

answered Dec 18, 2018 by Nabarupa

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How can I select date from a datepicker div using Selenium Webdriver?

Hey Jeevika, you can use following automation ...READ MORE

answered 4 days ago in Selenium by Abha
• 16,420 points
13 views
0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,220 points
352 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
259 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
627 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
255 views
+4 votes
1 answer

How can I configure Eclipse for using Selenium?

Follow the following steps to configure your ...READ MORE

answered Dec 12, 2018 in Selenium by Nabarupa
180 views
0 votes
1 answer

How can I login to flipkart using selenium?

Hey @Jino, glad you are liking selenium ...READ MORE

answered Dec 20, 2018 in Selenium by Nabarupa
420 views