2

I have a list of web elements that I defined as follows:

sellersList = browser.find_elements_by_class_name('gig-card-layout')

Each web element looks like this:

<div class="gig-card-layout">
    <div>
        <div class="gig-wrapper card" data-gig-id="gig_id" data-impression-collected="true">
            <a href="ref_link" target="_blank" class="media">...</a>
        <div class="seller-info text-body-2">...</div>
        <h3 class="text-display-7>...</h3>
        <footer>
            <a href="ref_link" target="_blank" class="price" title="$50">...</a>
        </footer>
        </div>
    </div>
</div>

I would like to access the price text located in the footer of each web element using a for loop.

How could I do that?

1 Answer 1

1

You can get the price elements directly using the below snippet.

# get all price elements
priceElems = driver.find_elements_by_css_selector(".gig-card-layout  footer a")

# iterate through all price elements and print the price
for priceElem in priceElems:
    print(priceElem.get_attribute('title'))

If you want to use the sellersList and iterate through the list then you can do the below

for seller in sellersList:
    print(seller.find_element_by_xpath(".//footer/a").get_attribute('title'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.