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

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.
主站蜘蛛池模板: 晴隆县| 库伦旗| 绥棱县| 大足县| 界首市| 澎湖县| 淅川县| 东丰县| 临江市| 玉屏| 南和县| 曲靖市| 五台县| 丹凤县| 宁陵县| 山东省| 武城县| 个旧市| 比如县| 昌黎县| 新密市| 文化| 余庆县| 石狮市| 平邑县| 利川市| 腾冲县| 开阳县| 南江县| 安阳县| 汪清县| 无为县| 青冈县| 静宁县| 霞浦县| 恩平市| 峨边| 水富县| 青海省| 香河县| 湖北省|