Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to select values from dropdown in Selenium

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 316
    Comment on it

    Value can be selected from the drop down, using the "Select" class:

    Select sel = new Select(driver.findElement(By.xpath("xpath_of_dropdown")));
    sel.selectByIndex(index_of_value_to_select);

    OR

    Select sel = new Select(driver.findElement(By.xpath("xpath_of_dropdown")));
    sel.selectByValue(value_to_be_selected);

    OR

    Select sel = new Select(driver.findElement(By.xpath("xpath_of_dropdown")));
    sel.selectByVisibleText(name_of_value);

    Eg: We have to select "March" from month dropdown

    sel.selectByIndex(3); // because march is on third index.

    sel.selectByValue(23); // Value associated with march is 23.

    sel.selectByVisibleText("March");

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: