1

I'm trying to check the url of an image, located in a div - in the 'background:' - in the CSS for the page. But when 'get' the CssValue and display it just shows blank.

The html for the div is:

<div class="Welcome">

<h3>Welcome</h3>
.......
</div>

...and the CSS for the div is:

div.Welcome {
background: rgba(0, 0, 0, 0) url("imageurl") no-repeat scroll center 25px;
float: left;
margin: 50px 20px 50px 150px;
padding-top: 230px;
width: 300px;
}

I've tried to locate as below:

WebElement WelcomeImg = driver.findElement(By className("Welcome"));

String WelImg = WelcomeImg.getCssValue("background");

Assert.assertTrue(WelImg.contains("imageurl"));

I've also tried with

("background-url");

Any help would be greatly appreciated

1
  • The URL is defined in background-image. Commented Oct 24, 2016 at 20:14

1 Answer 1

2

I think, you should try with new thing! Get the background image property and let me know whether it worked.

WebElement WelcomeImg = driver.findElement(By className("Welcome"));
String WelImg = WelcomeImg.getCssValue("background-image");
Assert.assertTrue(WelImg.contains("imageurl"));

Hope, it may help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.