0

Can anyone help me with exact code to iterate multiple elements & clicking it having same ID or XPath or css whatever just like we do findelements in selenium

  • What is your code so far? Where does it not work? – pavelsaman Oct 24 '21 at 16:49
  • Hi @pavelsaman I tried using browser.elements & await browser.findElements like below browser.elements('css selector','locator here', function (result) { result.forEach(e=>e.click()) }); also tried let ele= await browser.findElements("some loc") , ele.forEach(e => e.click()) something like that , I need exact code to click all the elements with same locator just like findElements in selenium – karthik kallu Oct 26 '21 at 08:06

1 Answers1

0

This format will click on each element found using elements()

async clickElements() {
        const list = '//div[@id = "test"]//div[@class = "row"]';
        this.api.useXpath();
        const results = this.api.elements('xpath', list);
        const listLength = results.value.length;
        for (let i = 0; i < listLength; i++) {
            const element = `//div[@id = "test"]")]//div[@class = "row"][${i + 1}]`;
            this.api.waitForElementVisible(element);
            this.api.click(element);
        }
    },