Issue
Trying to locate all elements on page
<i data-visualcompletion="css-img" class="x1b0d499 xep6ejk" style="background-image: url("https://static.xx.fbcdn.net/rsrc.php/v3/yd/r/A6Wu9TeIieI.png"); background-position: 0px -1304px; background-size: auto; width: 16px; height: 16px; background-repeat: no-repeat; display: inline-block;"></i>
Since attributes inside style such as background-position: 0px -1304px;
and ;background-image: url("https://static.xx.fbcdn.net/rsrc.php/v3/yd/r/A6Wu9TeIieI.png
changes very often i can't locate by style like this
style ='background-image: url("https://static.xx.fbcdn.net/rsrc.php/v3/yd/r/A6Wu9TeIieI.png"); background-position: 0px -1304px; background-size: auto; width: 16px; height: 16px; background-repeat: no-repeat; display: inline-block;'
driver.find_elements(By.CSS_SELECTOR, f"i[style='{style}']")
What I'm looking for is some kind of contains
including and
.
I.E
driver.find_elements(By.XPATH, f"//*[contains(@style,
'width: 16px; height: 16px; background-repeat: no-repeat; display: inline-block;')]")
AND Style Contains myOtherStyleHere
This is Facebook Marketplace three dots button
Solution
You can use logical and
operator inside the XPath locator, as following:
driver.find_elements(By.XPATH, "//*[contains(@style, 'width: 16px') and(contains(@style, 'height: 16px')) and(contains(@style, 'background-repeat: no-repeat')) and(contains(@style, 'display: inline-block'))]")
The above is example only. The idea is: you can use several contains
conditions while each of them contains some desired fixed condition.
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.