exists(selector)
This is a TDK feature
This is not supported in Testim's visual editor
This method checks that an element matching the given selector exists on the page:
selector
{string | TDKStepLocator} a CSS selector or smart locator.- returns: Promise that fulfills with
true
if the element exists on the page orfalse
if it doesn't.
Note: This method does not wait for the element to be available on the page like other control methods.
// ✅ checks if the given elementt is available on the page
const doesExist = await exists('.some-selector');
// ✅ assertion that an element exists on the page using `chai`
const loginPresent = await exists('.login-form');
expect(loginPresent).to.equal(true);
// ✅ assertion with locators
const userExists = await exists(l('user-name');
expect(userExists).to.equal(true);
// ❌ does not actually do anything since no one looks at the result
await exists('.some-selector');
// ❌ need to pass a selector or locator in
await exists();
Full Example
'use strict';
const expect = require('chai').expect;
const { go, exists, test, waitForElement } = require('testim');
test("exists" , async () => {
await go('http://jsbin.testim.io/quh/1');
await waitForElement('button');
const first = await exists('button');
expect(first).to.equal(true);
const second = await exists('my-element');
expect(second).to.equal(false);
});
Updated almost 3 years ago