click (target), clickAndWait (target) - Selenium IDE command

clickAndWait and click send a Javascript click event to the DOM element defined by the locator.

The difference between clickAndWait and click is that clickAndWait waits for a page load event after the click. So clickAndWait = click + waitForPageToLoad.

FAQ: How to click a button with a changing ID?

On some websites the ID of a button (or an element in general) is changing between different page loads (dynamic ID). This means the test case macro will fail at replay as the button has a new ID after each page refresh.

Solution: Typically some part of the ID remains constant e. g. post-123456 and post-555555. We can use XPath's starts-with or contains functions to search just for the stable part of the ID. So the selector will be something like this: //*[contains(@id, 'post-')].

Contains Example

Question from a Kantu user: I would like to make a macro that when I play it, it will open the first headline of the New York Times webpage (the one that always appears on the upper left hand side). Can I do that with your extension? Because when I recorded the macro, it would record the URL of the article that appeared at that moment, and when I played the same macro the following day, it did not work, because the headlines had changed on the front page.

Solution with "contains": On the New York Times page, the recorded click on the article headline creates a locator in the format //*[@id="topnews-100000005713971"]/h2/a. This includes a unique ID for each article. So if you want to click on the same link everyday (regardless of the article), use this modified locator: //*[contains(@id,"topnews-")]/h2/a

And how have we come up with //*[@id="topnews-100000005713971"]/h2/a in the first place? Where exactly does that appear?
Answer: During recording our Selenium IDE uses the link= as the default selector, as this is often the best selector - but other options are available in the target dropdown as well! These additional options are available during recording and before you switch to another macro. The reason for this is that the additional options are not saved. In other words, only one selector is saved in the macro, not the complete list of options.
Kantu offers different selectors during recording

The other option is to use image-driven test automation that works on optical recognition of screen elements rather than HTML elements. It can be a method to get around those peskily changing IDs. The Kantu Visual Web Automation software (not to be confused with the Kantu Selenium IDE) uses computer-vision and does exactly that.

clickAndWait and click Example

Command Target Pattern/Text
open https://a9t9.com/
click link=Free Web Automation -
clickAndWait link=Go To Next Page -

Works in

Kantu for Chrome Selenium IDE, Firefox IDE Classic

Related Demo Macros

Demo-Autofill, Demo-Frame

The ready-to-import-and-run source code of all demo macros can be found in the Github repository testmacros folder.

See also

storeEval, Web Automation Extension User Manual Selenium IDE commands, Classic Firefox Selenium IDE.

Anything wrong or missing on this page? Suggestions?

...then please contact us.

Kantu Selenium IDE for Chrome and Firefox - Web Test Automation
Subscribe to the a9t9 automation software newsletter . We'll send you updates on new releases that we're working on.