question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebElement#getCssValue does not return rgba value in case of hexa color

See original GitHub issue

🐛 Bug Report

When using WebElement#getCssValue the returned value is not necessarily a rgba value when the requested color is in fact an hexadecimal value, contrarily to what’s explained in the WebElement javadoc: https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/WebElement.java#L246-L265

Now I’ve not been able to track down in the W3C WebDriver specification if the color values should be systematically rgba or not, so maybe it’s just a javadoc issue.

To Reproduce

Detailed steps to reproduce the behavior: Request the CSS color value of an element containing an hexadecimal color.

Expected behavior

The color is returned as an RGBA value.

Test script or set of commands reproducing this issue

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
// The "connection" button, cf the following gif
WebElement element = driver.findElement(By.id("gb_70"));
// expected to be RGBA according to the javadoc
String color = element.getCssValue("border-top-color");
System.out.println("Color CSS value: " + color);
driver.quit();

google-button-border-color

Environment

OS: Linux Browser: Firefox Browser version: 69.0.3 Browser Driver version: GeckoDriver 0.25.0 Language Bindings version: Java 3.141.59

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pujaganicommented, Mar 30, 2021

Thank you for providing the details again. Apologies from my end. I misunderstood the issue here. Appreciate the clarification comment. It seems the values returned are dependent on the browser interpretation and implementation. I have updated the Javadoc appropriately.

1reaction
surlicommented, Mar 29, 2021

In both cases, I was unable to see the issue.

So apparently my issue description was not clear enough, but you show exactly the issue I had: I was expecting this method to always return RGBA and not RGBA or RGB. You can check the associated commit on our project, I had to change some test expectation from rgba value to rgb because of it: https://github.com/xwiki/xwiki-platform/commit/f6366253740a905147f21a7e43d901e7bce36f61

Now IMO the fix is just to clarify the javadoc to express that the value can be either rgba or rgb, since right now it says:

Color values should be returned as rgba strings

[EDIT: note that I created it as a bug since apparently this commit was related with an upgrade of selenium, so I wasn’t sure if it was a regression or not]

Read more comments on GitHub >

github_iconTop Results From Across the Web

getCssValue (Color) in Hex format in Selenium WebDriver
Get the value of a given CSS property. Color values should be returned as rgba strings, so, for example if the "background-color" property ......
Read more >
Behaviour of WebElement.getCssValue() - Google Groups
recently it now returns HEX values. * FirefoxDriver returns RGB values. * IEDriver returns HEX for everything except parameters set to values like...
Read more >
How to verify color of a web element in Selenium Webdriver?
We can verify the color of a webelement in Selenium webdriver using the getCssValue method and then pass color as a parameter to...
Read more >
getCssValue() method in Selenium Java with Examples
This post will discuss the getCssValue() method of the WebElement interface in ... One catch here is that color values would be returned...
Read more >
How to verify color of a web element in Selenium Webdriver
@Hello Nisha, you can discover the color of a web element and then verify it by using getCssValue() method, which take CSS attribute...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found