Support & information center

How to use CSS notation with testRTC scripts?

By default, testRTC enables using CSS notation when you want to refer to different DOM elements on your web application. This applies to script commands such as .setValue().click() and .waitForElementVisible().

This means that whenever you need to hook up to a DOM element in your application, but it for clicking a button, filling out a form entry or anything else, you need to use a selector. The default is CSS though XPath is also available.

If you have the ID of an HTML element, then life is simple. Lets assume we have a button with the id submit on it:

<button id="submit">Submit</button>
Code language: HTML, XML (xml)

Then its CSS selector is simply #submit and the button can be clicked in testRTC using the following nightwatch command:

client.click("#submit");
Code language: CSS (css)

While we prefer the use of ID’s to access elements, these are not always available and then you need to figure out a good CSS selector for it.

To learn more about CSS selectors and how to use them, we recommend this article.

Was this article helpful?

Related Articles