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
    • 520
    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
    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>

    Webdriver code for Selecting a Value using selectByIndex(Index);

    public class selectByIndexExample {
    public static void main(String args[]) {
    WebDriver driver = new FirefoxDriver () ;
    WebElement element=driver.findElement("Months"));
    Select se=new Select(element);</p>se.selectByIndex(10);

 0 Comment(s)

Sign In

Sign up using

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: