2

When I'm trying to get bgcolor using xpath I'm not getting the actual color.

HTML Code

   <div class="__title">Preferred 2:1 </div>

Selenium code:

String bgColor=New_AEMLocators.marketingBanner.getCssValue("background-color");

When I'm trying to print the bgColor,it printing rgba(0,0,0,0) But my bgcolor is white.

The text "Preferred 2:1" is in black color. Somehow it's printing that in the console.

Please help me in getting the exact bg color.

Thanks in advance.

1

The CSS attribute for the text color is simply "color", not bgcolor.

https://www.w3schools.com/cssref/pr_text_color.asp

Inspect the "___titie" class to double check it.

| improve this answer | |
1

I have tried this code for Google.ca and it worked:

driver.get("https://www.google.ca/")
String color = driver.findElement(By.id("gsr")).getCssValue("background-color");
System.out.println(color);

Output:

rgba(255, 255, 255, 1)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.