Skip to content

[🐛 Bug]: waitForExist changes the element obtained from $$ by index #14249

@k03mad

Description

@k03mad

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.10.1

Node.js Version

22.14

Mode

WDIO Testrunner

Which capabilities are you using?

{
    'browserName': 'chrome',
}

// or (does not affect)

{
    'browserName': 'chrome',
    'wdio:enforceWebDriverClassic': true,
}

What happened?

When using waitForExist on an element obtained from the $$ command by its index, the element may change to another one from this array of elements.

I think this issue began after element update was added in the following commit:
9c98ae9#diff-2b6bc02995e1bce24505124980c891370b8421d420f8bca937d92322c76161edR61

What is your expected behavior?

No response

How to reproduce the bug.

mkdir wdio-wait-exist-bug
cd wdio-wait-exist-bug
npm init wdio@latest . -- --yes

Insert the following code into the file: wdio-wait-exist-bug/test/specs/test.e2e.js

describe('test', () => {
    it('step', async () => {
        await browser.url('https://example.org/');

        await browser.execute(() => {
            const h1 = document.querySelector('h1');
            h1.insertAdjacentHTML('afterend', '<input name="input1">')
            h1.insertAdjacentHTML('afterend', '<input name="input2">')
        });

        await browser.pause(2000);

        const elem = await $$('input')[1];

        const name = await elem.getAttribute('name')
        console.log('—————————— \n name:', name);

        await elem.waitForExist();

        const nameAfterWaitForExist = await elem.getAttribute('name')
        console.log('—————————— \n nameAfterWaitForExist:', nameAfterWaitForExist);
    })
})

Run test: npm run wdio

Relevant log output

[0-0]  name: input1
[0-0] —————————— 
[0-0]  nameAfterWaitForExist: input2

Expected same element at logs

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

Labels

Bug 🐛help wantedIssues that are free to take by anyone interested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions