Loop action to next elements in page

Hi , how can loop same action to next elements

for example I want to enter to each product in this page https://www.amazon.com/s?k=sofa , copy title and store to csv ,

I’m able to do it for one product but how to do it for all products ?

my map

“Name”: “amazon”,
“CreationDate”: “2023-9-30”,
“Commands”: [
“Command”: “open”,
“Target”: “https://www.amazon.com/s?k=sofa&crid=FCQIUGJGZ5DH&sprefix=sof%2Caps%2C154&ref=nb_sb_noss_2”,
“Value”: “”,
“Description”: “”
“Command”: “clickAndWait”,
“Target”: “xpath=//[@id="search"]/div/div/div/span/div/div[5]/div/div/div/div/div/span/a/div/img",
“Value”: “”,
“Targets”: [
“css=#search > div.s-desktop-width-max.s-desktop-content.s-wide-grid-style-t1.s-opposite-dir.s-wide-grid-style.sg-row > div.sg-col-20-of-24.s-matching-dir.sg-col-16-of-20.sg-col.sg-col-8-of-12.sg-col-12-of-16 > div > span.rush-component.s-latency-cf-section > div.s-main-slot.s-result-list.s-search-results.sg-row > div:nth-child(9) > div > div > div > div > div.s-product-image-container.aok-relative.s-text-center.s-image-overlay-grey.puis-image-overlay-grey.s-padding-left-small.s-padding-right-small.puis-spacing-small.s-height-equalized.puis.puis-v20azwp0smsgc01ytmkntf1rk7n > span > a > div > img”
“Description”: “”
“Command”: “storeText”,
“Target”: “id=title”,
“Value”: “!CsvLine”,
“Description”: “”
“Command”: “csvSave”,
“Target”: “data.csv”,
“Value”: “”,
“Description”: “”

any answer any answer

If you’re a newbie without IT knowledge. Do steps by step:

  1. Understand HTML Hierarchy Basic, HTML Basics (with examples)
  2. Understand Locators: ui.vision/rpa/docs/selenium-ide/locators
  1. How to find element with xpath in chrome developer tools:
    How to Find XPath in Chrome Browser - Scientech Easy
    How To Use Xpath In Selenium: Complete Guide With Examples | LambdaTest
  1. My test:
    First product: xpath=//div[@data-index=“2” and @data-component-type=“s-search-result”]
    Next product,xpath=//div[@data-index=“3” and @data-component-type=“s-search-result”]

    Before loop, you need define a variable (to assign to data-index) using Store function with value = 2.
    Example: store | 2 | dataIndex
    you can use while loop while, endWhile - FlowControl - Selenium IDE Commands Tutorial
    In loop, you need verify element exist with target.
    Example: assertElementPresent, assertElementNOTPresent, verifyElementPresent (assert Element Present, assert Element NOT Present) - Selenium IDE Commands Tutorial
    Verify element using xpath= //div[@data-index=“${dataIndex}” and @data-component-type=“s-search-result”]
    If exist, get title: xpath=//div[@data-index=“2” and @data-component-type=“s-search-result”]//descendant::h2//span
    if not exist, it reachs end, exist with break command
    Then increase variable dataIndex by 1 using executeScript_Sandbox function:
    executeScript_Sandbox | return Number(${dataIndex }) + 1; | dataIndex