Selenium WebDriver 3 Practical Guide
上QQ阅读APP看书,第一时间看更新

The isEnabled() method

The isEnabled action verifies whether an element is enabled on the web page and can be executed on all the WebElements. The API syntax for the isEnabled() method is as follows:

boolean isEnabled()

The preceding method returns a Boolean value specifying whether the target element is enabled on the web page. The following is the code to verify whether the Search box is enabled, which obviously should return true in this case:    

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

The preceding code uses the isEnabled() method to determine whether the element is enabled on a web page. The preceding code returns true for the Search box:  

Search box is enabled: true