How to get style attribute with Browser Library

So, i’m trying to make my automation validate the color of a text element using Browser Library
Then I tried the following line:

${element_style}=  Get Attribute   xpath=//span[contains(text(),"text to be validated")]   style 
${style_txt}=  Get Text   ${element_style}
Should Contain   ${style_txt}   rgb(1,1,1)

But that just returns nothing for ${element_style} variable

If you are after the style then If I’m not mistaken you can use the ‘Get Style’ keyword that the browser library offers, so it would look something like this:

${element_style}=       Get Style      //span[contains(text(),"text to be validated")]      color
Should Contain      ${element_style}        rgb(1,1,1)

This should work provided the XPath is correct for returning the “style color value” for that element.

1 Like