Issue
From this page: https://www.realestate.com.kh/buy/, which looks like this in the inspector:
I'm trying to extract all elements of class css-1uuzwjq eq4or9x0
into a list in order to click on the elements and further explore.
I have this code, in which I try to get the elements by their Xpath:
ads = browser.find_elements_by_class_name('css-1uuzwjq eq4or9x0')
for ad in ads:
ad.click()
However, the list always ends up empty. What am I doing wrong?
Solution
class attribute holds multiple classes , each class is separated by space. In your case, 'css-1uuzwjq eq4or9x0' are two classes not one
you can find it as :#
- xpath
in xpath it validates the class attribute value is exactly the same
//*[@class="css-1uuzwjq eq4or9x0"]
- CSS
in css it checks for element that contains both the mentioned class, each class should be mentionedwith a dot
.css-1uuzwjq.eq4or9x0
if you want exact match , use the below locator as it checks the class attribute value to be exact
[class="css-1uuzwjq eq4or9x0"]
using class locator
browser.find_elements_by_class_name('css-1uuzwjq.eq4or9x0')
calss locator uses css locator under the hood , so when you pass a class name, it just adds 'dot' in front of it . so to make it a valid locator pass all classes by replacing space with dot
Answered By - PDHide
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.