How to verify if WebElement is selected or not How to verify if WebElement is selected or not selenium selenium

How to verify if WebElement is selected or not


To verify if the WebElement is selected or not you can try:

    String attr = driver.findElement(By.id("user-settings-price-preview-checkbox")).getAttribute("class");    if(attr.contains("active"))        System.out.println("WebElement selected");    else        System.out.println("WebElement NOT selected");


Code snippet:

String classAttribute = driver.findElement(By.id("user-settings-price-preview-checkbox")).getAttribute("class");boolean isItemSelected = classAttribute.endsWith("active");Assert.assertTrue(isItemSelected);