- 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.
推薦閱讀
- Spring Boot 2.0 Projects
- 計(jì)算機(jī)網(wǎng)絡(luò)與數(shù)據(jù)通信
- 農(nóng)產(chǎn)品物聯(lián)網(wǎng)研究與應(yīng)用
- 面向物聯(lián)網(wǎng)的嵌入式系統(tǒng)開發(fā):基于CC2530和STM32微處理器
- 網(wǎng)絡(luò)安全技術(shù)與解決方案(修訂版)
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- 城域網(wǎng)與廣域網(wǎng)(第2版)
- 網(wǎng)絡(luò)AI+:2030后的未來網(wǎng)絡(luò)
- Learning Windows 8 Game Development
- Getting Started with nopCommerce
- 5G+區(qū)塊鏈
- 現(xiàn)代通信系統(tǒng)(第5版)
- 云計(jì)算技術(shù)與標(biāo)準(zhǔn)化
- LwIP應(yīng)用開發(fā)實(shí)戰(zhàn)指南:基于STM32
- Selenium WebDriver 3 Practical Guide