Method Name: selectByVisibleText
Syntax: select.selectByVisibleText(Text);
Purpose: To Select the options based on text, matching with the argument given by user., it will try to match the VisibleText which will display in dropdown.
The below is the sample HTML code Example:
HTML Code:
<title>Select Example by Index value</title>
<select name="Days"><option value="0" selected=""> Please select</option>
<option value="1">Mon</option>
<option value="2">Tue</option>
<option value="3">Wed</option>
<option value="4">Thu</option>
<option value="5">Fri</option>
<option value="6">Sat</option>
<option value="7">Sun</option>
</select>
Web-driver code for Selecting a Value using selectByVisibleText(Text);
public class selectByVisibleTextExample {
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("Days"));
Select se=new Select(element);
se.selectByVisibleText("Wed");
}
}
0 Comment(s)