Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Click buttons on page until all will be removed

My scenario: On a page, I have multiple buttons. After button is clicked, page is reloaded without the clicked button.

I have a problem with the implementation of a proper solution.

Currently I have something like this:

let selector = 'selector for All button on page';
let buttons = browser.$$(selector);

for (int i = 0; i < buttons.length; i++) {
    let button = browser.$(selector);
    button.moveToObject();
    button.waitForVisible();
    button.click();
    browser.waitToVisible(elementAfterPageRefresh);
}

The problem occurs after the first iteration. Sometimes it works by only moving to the button, sometimes the script does not even click the second button.

What is the proper way to solve my problem with webdriverio?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Can you also provide a error traceback from the console after running your code? I presume you are facing the notorious "Stale element reference..." error.

First of all, a WebdriverIO driver, as well as a WebdriverJS one (its predecessor) will always lose the reference (element ID) to previously queried element/elements after the browser executes a page reload.

So according to Christian Bromman (@ChristianB), you will have to do something along the lines of:

runner
.init()
.url('https://www.google.dk/search?q=burrito')
.getText(".r").then(function(res){ // given `.r` is the <a /> tag on google search page
    res.value.forEach(function(elem){
        console.log(elem);
        clicks.push(
            runner
                .click('=' + elem.ELEMENT) // use link text selector to query the element again
                .pause(5000)
                .back()
                .pause(2000)
        );
    });

    return q.all(clicks);
});

I presume this is only for training purposes as I cannot understand why clicking a series of buttons would each trigger a page refresh. :)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!