Get element count then getting values of those elements

Hello all

I’m trying to help a friend who owns a local coffee roasting company get his competitors coffee pricing. Since the products could change, I thought of using get element count to get the header values then iterating through that to get the details of each product but I’m failing at the for statement. There are 14 products. Here is what I have so far:

New Browser chromium headless=false
New Context
New Page All RSR Coffees – Ross Street Roasting Co.
${ProductCount}= Get Element Count //div[@class=“o-layout__item u-1/1 u-1/2@phab u-1/3@tab”]
Log ${ProductCount}
FOR ${Product} IN @{ProductCount}
${ProductName}= Get Text //h2[@class=“product-card__title f-family–body f-caps–false f-space–0”]
Log ${ProductName}
END

Any help would be greatly appreciated!

Ok, I submitted that prematurely because I figured it out. Just chaning the @ to $ to look at the ProductCount did the trick. The issue I’m having now is not returning all 14 product names! I set strict mode to false, since I got an error on that, but it’s still only returning the first name.

Hi @bing098911 !

I would do it like this. You can use that ${coffee} as base locator for its subsequent elements.

    New Browser    chromium    headless=false
    New Page    https://www.rossstreetroasting.com/collections/ross-street-roasting-coffee-products
    ${coffees}=    Get Elements    //div[contains(@class, "product-card-top")]
    FOR    ${index}    ${coffee}    IN ENUMERATE    @{coffees}    start=1
        ${name}=    Get Attribute    ${coffee} > a    title
        Log To Console    ${index}: ${name}
    END
1 Like

Awesome! I will give that a try. Thank you @mika !