I.click / I.doubleclick

Click or double click on an element.

When the click triggers a page load:

If the click triggers a page load, the test will wait until the page load is complete. Note that the time taken to execute the command includes the page load time.

When the click triggers a page load in a new tab:

If the click opens a page in a new tab, the browser will automatically be switched to the new tab.

Usage

I.click(target);
I.doubleClick(target);
Parameter Type Remarks
target string Keyword to identify the element to click.
This is case-insensitive.

# Click on element with text

I.click("Log In")

Click on an element seen as "Log In".

# Click on images / icons using aria-label or title

Image / icon can be clicked on using the aria-label or title attribute set on the element.

We'd strongly recommend setting both, because title gives your element a helpful tooltip for visual users, and aria-label makes your application friendly to people who use accessibility tools.

Here, we will use this plus button with the tooltip "Add" for illustration:

You can click on the button using its tooltip like this:

I.click("Add")

# Click on element using CSS / XPATH

I.click(".login-btn")

Click on an element with the CSS class login-btn.

Use sparingly.
Use hard selectors like CSS / XPATH sparingly because it makes your tests fragile and harder to read and maintain.