Hey @Rishab, you can take a look at the following code.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonShoping {
public static void main(String[] args) throws InterruptedException
{
//You mention the path to your chromedriver or geckodriver
System.setProperty("webdriver.chrome.driver","C:\\Users\\priyj_kumar\\Downloads\\chromedriver.exe");
//Create an instance of your chromedriver named driver
WebDriver driver = new ChromeDriver();
//Open facebook
driver.get("https://www.facebook.com");
//Create an instance of select and specify the webelement
org.openqa.selenium.support.ui.Select dropdown = new org.openqa.selenium.support.ui.Select(driver.findElement(By.id("day")));
// 1. You can select by value
dropdown.selectByValue("6");
// 2. You can select by index, you need to verify the index as it starts with 0 or 1
dropdown.selectByIndex(6);
// 3. You can select by Visible Text
dropdown.selectByVisibleText("6");
}
}
Hope this helps you.