The isSelected method returns a boolean value if an element is selected on the web page and can be executed only on a radio button, options in select, and checkbox WebElements. When executed on other elements, it will return false. The API syntax for the isSelected() method is as follows:
boolean isSelected()
The preceding method returns a Boolean value specifying whether the target element is selected on the web page. The following is the code to verify whether the Search box is selected on a search page:
@Testpublic void elementStateExample() { WebElement searchBox = driver.findElement(By.name("q")); System.out.println("Search box is selected: " + searchBox.isSelected());}
The preceding code uses the isSelected() ...