What can be the Xpath to get the background-image CSS Property of a DIV tag whose ID is mentioned in (selenium webdriver)?
Ex: (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)
I don't get your question, please format and expand a bit, it's kind of vague to me.
I assume you want to ask one of the following questions, but not sure which.
background-image
CSS Property of a div
using Selenium?Answer: Use Selenium's native GetCssValue()
(C#), css_value
(Ruby), or equivalent method in other language bindings.
IWebElement abc = driver.FindElement(By.XPath("//[@id='abc']")); // use XPath as you requested
string imageUrl = abc.GetCssValue("background-image");
div
element by its background-image
CSS property using XPath?Answer: If you don't want to use ID (which you should in this example case), you can totally do it in CssSelector or XPath. (XPath is the last option you should choose though)
IWebElement abc = driver.FindElement(By.XPath("//div[contains(@style, 'background-image: url(http://test.com/images/abc.png);')]"));
background-image
?Answer: Not really useful for Selenium, but here you have it: //div[@id='abc']/@style
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With