0

I need to make a script that checks if all h1 tags in a page are of a certain hex color. If they are not, test fails. What are the available options for doing this?

I'm using selenium with java

0
0

It depends on how is the color displayed on each h1. Assuming it is on the style attribute:

String color = "background-color: #ff6347";
List<WebElement> allH1 = driver.findElements(By.cssSelector("h1"));

Boolean allHaveExpectedColor = 
          allH1.parallelStream() // Let's look at all elements in parallel
          allMatch( // Let's verify all of them match some condition
              elem -> // Given we are looking into a H1 element
              elem.getAttribute("style"). // Let's get the style attribute
                    contains(color) // And check if it contains the color mark
));

Assert.assertTrue(allHaveExpectedColor, "Some H1 does not have the expected color");

If the color is displayed some other way, you just need to change the lambda function.