How to find any element based on css class property property in selenium
I need to find an element based on a background image, see screenshot for reference.
<em unselectable="on" class="x-btn-split">
...
</em>
Style:
em.x-btn-split
{
background-image: url("/EXT/theme/sfdc/images/button/split_mutton_arrow.png");
}
I need to find an element that has a background image like "/EXT/theme/sfdc/images/button/split_mutton_arrow.png"
+3
source to share
1 answer
From what is given, it looks like you can just check the class here:
driver.find_element_by_css_selector("em.x-btn-split")
If you insist on checking background-image
, you will need to find all tags em
and filter them by checking the CSS property background-image
in a loop:
value_to_find = "/EXT/theme/sfdc/images/button/split_mutton_arrow.png"
try:
em = next(em for em in driver.find_elements_by_css_selector("em.x-btn-split")
if em.value_of_css_property("background-image") == value_to_find)
print("Found!")
print(em)
except StopIteration:
print("Not Found!")
(Examples in Python)
0
source to share