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

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 508
    Comment on it

    Method Name: selectByIndex

    Syntax: select.selectByIndex(Index);

    **Purpose: To Select the option based on the index given by the user. There is an index for each attribute called "values"

    The below is the sample html code using index
    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 selectByIndex(Index);

    public class selectByIndexExample {
    
    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);</p>se.selectByIndex(10);
    
    }}
    

 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: