I am using selenium + chrome web driver to load a dynamic page:
self.driver.get(url)
time.sleep(3) # not sure if I need to add this wait, so the .js loads the page?
Once the page is loaded, I want to get a list of all cards available on the page and then iterate through each card and get its title:
cards = self.driver.find_elements_by_css_selector('div.my-card')
for card in cards:
title = card.find_element_by_css_selector('h2.title::text').get() # <-- does not work
desc = card.find_element_by_css_selector('div.desc::text').get() # <-- does not work
# more fields that I need within this card
find_elements_by_css_selector
seems to be a driver
method... I am not sure how to apply these selector to card (the type card is WebElement
).
Sample page:
<div class='my-card'>
<h2 class='title'>title 1</h2>
<div class='desc'>desc 1</div>
</div>
<div class='my-card'>
<h2 class='title'>title 2</h2>
<div class='desc'>desc 2</div>
</div>
<div class='my-card'>
<h2 class='title'>title 3</h2>
<div class='desc'>desc 3</div>
</div>