4

I grabbed this element using selenium webDrive:

<div class="body" style="background-image: url('http://d1oiazdc2hzjcz.cloudfront.net/promotions/precious/2x/p_619_o_6042_precious_image_1419849753.png');">

how can I fetch the value: http://d1oiazdc2hzjcz.cloudfront.net/promotions/precious/2x/p_619_o_6042_precious_image_1419849753.png ?

I'm not sure as this is an inner value, and not just an "src" attribute.

2
  • possible duplicate of stackoverflow.com/questions/14013131/… Commented Dec 29, 2014 at 12:15
  • I hope you are looking selenium-java combination answer.please remove the javascript tag people are answering in javascript Commented Dec 29, 2014 at 12:20

3 Answers 3

7

getCssValue(); will help you

 WebElement img = driver.findElement(By.className('body'));
 String imgpath = img.getCssValue("background-image");

then you can split the unwanted string "url('"

PS : Remove the javascript tag in your question

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

2 Comments

how can I fetch with regex the url itself? url('http://d1oiazdc2hzjcz.cloudfront.net/promotions/precious/2x/p_619_o_6042_precious_image_1419849753.png');">
4

Try this

var imgString = $(".body").css('background-image');
console.log (imgString.split("(")[1] // remove open bracket
                      .split(")")[0] // remove close bracket
             );

Fiddle

7 Comments

v=element(By.css('.icon.delete')); v.getCssValue("background-image").then (x) -> console.log x
what language is this? I didn't get ??
I am giving the answer in the way of jquery
this is not suitable for your question
@ji-ruh - The OP tagged javascript on time of posting the question. SO i answered in javascript, Yup later he untag the javascript \
|
0

You can try the following

some_variable=self.driver.find_element_by_xpath("//div[@class='body' and contains(@style,'url')]")
some_variable2=some_variable.get_attribute('style')

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.