Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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

Example:

<div id="abc", style="width: 538px !important; height: 242px !important; background-image: url(http://test.com/images/abc.png); position: relative; background-position: 0% 0%;>

I want to find this image with url: http://test.com/images/abc.png

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
add comment

1 Answer 1

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(By.id("abc"));
String bgImage = element.getCssValue("background-image");
share|improve this answer
add comment

Your Answer

 
discard

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.