Reputation: 67
I want to verify if WebElement is selected or not. This element exist (when is selected) in HTML as:
<span id="user-settings-price-preview-checkbox" class="user-settings-selector-checkbox active"></span>
and when is not selected:
<span id="user-settings-price-preview-checkbox" class="user-settings-selector-checkbox"></span>
How can I verify it using selenium and TestNG?
Upvotes: 4
Views: 3768
Reputation: 2799
Code snippet:
String classAttribute = driver.findElement(By.id("user-settings-price-preview-checkbox")).getAttribute("class");
boolean isItemSelected = classAttribute.endsWith("active");
Assert.assertTrue(isItemSelected);
Upvotes: 0
Reputation: 193188
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");
Upvotes: 1