Grubsniff
Grubsniff

Reputation: 1

.click function passes When step, but isn't actually clicking the element in the browser

I'm currently trying to script some automation tests.

I've hit a block with what should be a simple checkbox click...

The issue is the test run passes the step, but in the browser the "click" hasn't actually occurred.

POM

    optionClick(optionValue){
        const option = $('//input[@type="checkbox"]').$('..').$('label').$('//span[contains(text(), "'+optionValue+'")]');
        option.waitForDisplayed(2000);
        const optionSelect = $('//input[@type="checkbox"]').$('..').$('label').$('//span[contains(text(), "'+optionValue+'")]');
        optionSelect.click();
    }

Feature is - And I select the 'Create' option

the html element I'm trying to click is as follows: enter image description here

Upvotes: 0

Views: 208

Answers (1)

Ray
Ray

Reputation: 1214

The click function is asynchronous. If you don't do an await or wrap the click call in a promise then the action will take place synchronously meaning your test will move on and will probably finish before the click actually takes place.

What you need to do is:

        await optionSelect.click();

Upvotes: 1

Related Questions