- 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.
推薦閱讀
- 自動駕駛網絡:自智時代的網絡架構
- 物聯網安全(原書第2版)
- 從區塊鏈到Web3:構建未來互聯網生態
- 網絡創新指數研究
- 物聯網概論(第2版)
- 信息通信網絡建設安全管理概要2
- 面向物聯網的嵌入式系統開發:基于CC2530和STM32微處理器
- 面向云平臺的物聯網多源異構信息融合方法
- NB-IoT物聯網技術解析與案例詳解
- 物聯網之霧:基于霧計算的智能硬件快速反應與安全控制
- Microservice Patterns and Best Practices
- CCNP TSHOOT(642-832)認證考試指南
- 轉化:提升網站流量和轉化率的技巧
- Hands-On Bitcoin Programming with Python
- Cisco無線局域網配置基礎