Selenium Java to select dropdown choice using selectByValue() method
KW.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

class KW
{
    public static void main(String[] args) throws InterruptedException 
    {   
        System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.navigate().to("https://kodingwindow.com/testapp/");
        Thread.sleep(1000);
        Select country = new Select(driver.findElement(By.name("country")));
        country.selectByValue("germany");
    }
}
Advertisement