How To Fetch `style="background-image: Url` Using Selenium Webdrive?
I grabbed this element using selenium webDrive:
Solution 1:
getCssValue(); will help you
WebElementimg= driver.findElement(By.className('body'));
Stringimgpath= img.getCssValue("background-image");
then you can split the unwanted string "url('"
PS : Remove the javascript tag in your question
Solution 2:
Try this
var imgString = $(".body").css('background-image');
console.log (imgString.split("(")[1] // remove open bracket
.split(")")[0] // remove close bracket
);
Solution 3:
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')
Post a Comment for "How To Fetch `style="background-image: Url` Using Selenium Webdrive?"