Krish Krishna
Krish Krishna

Reputation: 317

Get background color from src in selenium WebDriver

The x-path is like < img id="" src="/A/A/B.png" style="">

I am required to find the color of the image , the style does not contain anything about color. It contains information only about height,width.

I am sure in the src path the fill attribute would be present.But how am I suppose to get till that?

Here is what i think of doing:

String css = driver.findElement(By.Xpath("..blah../img").getCSSValue("background-color");

but i get 'transparent' as answer .How do i get over it?

Upvotes: 2

Views: 9095

Answers (1)

Stan
Stan

Reputation: 3461

This will definetely works:

driver.findElement(By.xpath("..blah../img")).getCssValue("background-color").toString();

The problem is either your image is really transparent or color is defined in its parent.

Upvotes: 2

Related Questions