Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webdriver.IO - check in a non-blocking way whether an element exists

Rookie question. I am using webdriver.io to write Appium end to end tests.

I am using these commands to check the presence of an element:

  • $(selector)
  • browser.waitForVisible(selector, timeout, waitForAppearOrDisappear);
  • browser.element('selector')

They all block my tests if the element is not found.

How can I check whether an element exists in a particular moment without blocking the test execution?

I cannot find anything in the (concise) documentation.

PS. This should do the trick browser.findElement(By.css('[data-qa="some-id"]')); but it's not a wdio command. (findElement and By are not recognized)


npm dependencies:

"appium": "^1.10.0",
"appium-doctor": "^1.6.0",
"wdio-appium-service": "^0.2.3",
"wdio-jasmine-framework": "^0.3.8",
"wdio-spec-reporter": "^0.1.5",
"webdriverio": "^4.14.1",
like image 942
Gabe Avatar asked Oct 31 '25 16:10

Gabe


1 Answers

Use findElements instead - https://webdriver.io/docs/api/element/$$.html:

$$(selector)

This should return you an empty array if the element can't be found, it should not cause a failure though.

like image 133
Ardesco Avatar answered Nov 03 '25 20:11

Ardesco