Gautam Bothra
Gautam Bothra

Reputation: 625

Assert color value is correct or not in selenium java

I am using selenium using java. I am new to selenium. I have a class named connected which contains a symbol with green.I want to assert that if the symbol turned to green or not.

Here is my code:-

 Boolean connectionSymbolGreenValue = driver.findElement(By.className("connected")).isEnabled();
    System.out.println("Green Signal"+connectionSymbolGreenValue);
    Assert.assertTrue(connectionSymbolGreenValue);

I have tried this code. If condition Fails then also it is returning true. Is there any error in my code? Can anyone suggest any solution?

Upvotes: 0

Views: 867

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193368

As you are trying to identify a class named connected which contains a symbol with green invoking .isEnabled() method may not solve our purpose.

.isEnabled()

.isEnabled() validates if the element currently enabled or not? This will generally return true for everything but disabled input elements.

Solution

Try to identify an attribute(style) which uniquely identifies the attribute_containing_greenness_value of the symbol, then extract the String value and invoke Assert.assertTrue() comparing with actual_greenness_value as follows :

String connectionSymbolGreenValue = driver.findElement(By.className("connected")).getAttribute("attribute_containing_greenness_value");
System.out.println("Green Signal"+connectionSymbolGreenValue);
Assert.assertTrue(connectionSymbolGreenValue.equalsIgnoreCase("actual_greenness_value"));

Upvotes: 4

Related Questions