官术网_书友最值得收藏!

The isSelected() method

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:

@Test
public void elementStateExample() {
WebElement searchBox = driver.findElement(By.name("q"));
System.out.println("Search box is selected: "
+ searchBox.isSelected());
}

The preceding code uses the isSelected() method. It returns false for the Search box, because this is not a radio button, options in select, or a checkbox. The preceding code returns false for the Search box:

Search box is selected: false
To select a Checkbox or Radio button, we need to call the WebElement.click() method, which toggles the state of the element. We can use the  isSelected() method to see whether it's selected.
主站蜘蛛池模板: 龙泉市| 闵行区| 共和县| 长兴县| 大名县| 巴楚县| 仙游县| 浦北县| 余姚市| 昌吉市| 乐安县| 阜康市| 建湖县| 太康县| 环江| 惠州市| 新津县| 聂荣县| 保山市| 柯坪县| 南陵县| 兴业县| 翼城县| 淮安市| 鄂托克前旗| 谢通门县| 定结县| 大港区| 吕梁市| 乌拉特后旗| 浦江县| 镇平县| 泰和县| 湖州市| 土默特右旗| 台安县| 邯郸市| 长泰县| 惠来县| 商城县| 浦城县|