- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 186字
- 2021-08-13 16:08:12
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.
推薦閱讀
- GPS/GNSS原理與應用(第3版)
- Truffle Quick Start Guide
- Hands-On Chatbots and Conversational UI Development
- 物聯網信息安全
- Web Application Development with R Using Shiny
- 正在爆發的互聯網革命
- Mastering JavaFX 10
- OMNeT++與網絡仿真
- Kong網關:入門、實戰與進階
- Unity Artificial Intelligence Programming
- 移動物聯網:商業模式+案例分析+應用實戰
- SRv6網絡部署指南
- 物聯網,So Easy!
- 黑客與反黑工具使用詳解
- 互聯網安全的40個智慧洞見(2018)