Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Selenium Web-driver Syntax for Selecting a Value using selectByValue method

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 609
    Comment on it

    Method Name: selectByValue
    Syntax: select.selectByValue(Value);
    Purpose: To Select the options based on value, matching with the argument given by user.

    The below is the sample html code Example:
    HTML Code:

    <title>Select Example by Index value</title>
    <select name="Months"><option value="0" selected=""> Please select</option>
    <option value="1">Jan</option>
    <option value="2">Feb</option>
    <option value="3">Mar</option>
    <option value="4">Apr</option>
    <option value="5">May</option>
    <option value="6">Jun</option>
    <option value="7">Jul</option>
    <option value="8">Aug</option>
    <option value="9">Sept</option>
    <option value="10">Oct</option>
    <option value="11">Nov</option>
    <option value="12">Dec</option>
    </select>
    

    Webdriver code for Selecting a Value using selectByValue(Value);


    public class selectByValueExample {
    public static void main(String args[]) {
    WebDriver driver = new FirefoxDriver () ;
    driver.manage().window().maximize();
    driver.get("file:///C:/Users/Piyush/Desktop/Months.html");
    WebElement element=driver.findElement(By.name("Months"));
    Select se=new Select(element);
    se.selectByValue("Aug");
    }
    }
    

 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: