What are the various methods available under Select class in Selenium?

Software TestingAutomation TestingSelenium Web Driver

The various methods available under Select class in Selenium are listed below −

  • selectByVisibleText(String args)

    This method is most commonly used in dropdowns. It is very simple to select an option in a dropdown and multiple selection box with this method. It takes a String parameter as argument and returns no values.

    Syntax −

    Select s = new Select(driver.findElement(By.id("<< id exp>>")));
    s.selectByVisibleText("Selenium");
  • selectByIndex(String args)

    This method takes the index of the option to select in the dropdown. It takes an int parameter as argument and returns no values.

    Syntax −

    Select s = new Select(driver.findElement(By.id("<< id exp>>")));
    s.selectByIndex(1);
  • selectByValue(String args)

    This method takes the value of the option to select in the dropdown. It takes a String parameter as argument and returns no values.

    Syntax −

    Select s = new Select(driver.findElement(By.id("<< id exp>>")));
    s.selectByValue(“Testing”);
  • getOptions()

    This method fetches all the options under the select tag in form of list of web elements. It has no arguments.

    Syntax −

    Select s = new Select(driver.findElement(By.id("<< id exp>>")));
    s.getOptions();
  • deSelectAll()

    This method is used for multi select dropdown and removes all the options selected.

    Syntax −

    Select s = new Select(driver.findElement(By.id("<< id exp >>")));
    s.deSelectAll();
  • deselectByVisibleText(String args)

    This method is used to deselect all options from a dropdown on basis of the text displayed that is similar to the argument. It takes a String parameter as argument and returns no values. This method is used for multi select dropdown.

    Syntax −

    Select s = new Select(driver.findElement(By.id("<< id exp>>")));
    s.deselectByVisibleText("Selenium");
  • deselectByIndex(String args)

    This method takes the index to deselect option in the dropdown. It takes an int parameter as argument and returns no values. This method is used for multi select dropdown.

    Syntax −

    Select s = new Select(driver.findElement(By.id("<< id exp>>")));
    s.deselectByIndex(1);
  • deselectByValue(String args)

    This method takes the value to select options in the dropdown. It takes a String parameter as argument and returns no values. This method is used for multi select dropdown.

    Syntax −

    Select s = new Select(driver.findElement(By.id("<< id exp>>")));
    s.deselectByValue(“Testing”);
raja
Published on 11-Jun-2020 15:14:02
Advertisements