1// Create object of the Select class
2Select se = new Select(driver.findElement(By.xpath("//*[@id='oldSelectMenu']")));
3
4// Select the option with value "6"
5se.selectByValue("6");
6
1package newpackage;
2import org.openqa.selenium.WebDriver;
3import org.openqa.selenium.firefox.FirefoxDriver;
4import org.openqa.selenium.support.ui.Select;
5import org.openqa.selenium.By;
6
7public class accessDropDown {
8 public static void main(String[] args) {
9 System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
10 String baseURL = "http://demo.guru99.com/test/newtours/register.php";
11 WebDriver driver = new FirefoxDriver();
12 driver.get(baseURL);
13
14 Select drpCountry = new Select(driver.findElement(By.name("country")));
15 drpCountry.selectByVisibleText("ANTARCTICA");
16
17 //Selecting Items in a Multiple SELECT elements
18 driver.get("http://jsbin.com/osebed/2");
19 Select fruits = new Select(driver.findElement(By.id("fruits")));
20 fruits.selectByVisibleText("Banana");
21 fruits.selectByIndex(1);
22 }
23}
24
1import org.openqa.selenium.By;
2import org.openqa.selenium.WebDriver;
3import org.openqa.selenium.chrome.ChromeDriver;
4
5public class MyClass {
6
7 public static void main(String[] args) {
8 String baseUrl = "http://demo.guru99.com/test/link.html";
9 System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
10 WebDriver driver = new ChromeDriver();
11
12 driver.get(baseUrl);
13 driver.findElement(By.linkText("click here")).click();
14 System.out.println("title of page is: " + driver.getTitle());
15 driver.quit();
16 }
17
18}
19