Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What would be the Xpath to get the background-image CSS Property of a DIV tag whose ID is mentioned in Selenium Webdriver?


<div id="abc", style="width: 538px !important; height: 242px !important; background-image: url(; position: relative; background-position: 0% 0%;>

I want to find this image with url:

share|improve this question
Not sure what you're trying to do here. Do you know the div's ID, and you want to verify the CSS background-image property? Or do you only know the CSS background-image property, and you want to use that to identify the div and then do some other testing on it? – vincebowdren Sep 17 '13 at 10:19

Typically HTML IDs are unique; if you know the ID, you do not need to know the element tag. Of course it is possible to write a web page that uses duplicate IDs. If your web page has duplicate IDs, you should complain to the developer. For the rest of my answer, I will assume unique IDs.

According to this, XPath doesn't actually know anything about CSS styles.

I also assume you are using the Java language binding. I Googled for "webdriver webelement"; the second link took me to the WebElement javadoc, where I found the getCssValue method. Try this:

WebElement element = driver.findElement("abc"));
String bgImage = element.getCssValue("background-image");
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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