Checking the presence of an element in a web page?

Does anyone know how to check the presence of an element in a web page? I need a grroovy example.

FYI exists() doesn’t work because it waits for the configured timeout to end, I need a way to return immediately.

I ended up doing this:

				timeouts(1 * 1000)
				if (exists(byXpath(...)) {
				timeouts(40 * 1000)

Is there any better and more elegant way to do this?

If you need an immediate result, you can do the following:

try {
} catch(Exception ex) {
1 Like

Please also check

It has an example with waiting for an element which can be missing for some time while a page is loading

// set timeout for explicit waits
setFluentWaitTimeout(3 * 1000)
// check the existence of element - if it might be missing
1 Like