Dawid Ohia
Dawid Ohia

Reputation: 16445

How to get visible elements with WebDriverIO

I my tests I am using WebDriverIO. I want to get all elements with class form_error that are visible.

I try something like this:

$$('.form_error:visible')

but the :visible filter is not a valid webdriverio selector construct. How to achieve that?

Upvotes: 0

Views: 2011

Answers (1)

Kevin Lamping
Kevin Lamping

Reputation: 2269

WebdriverIO uses CSS selectors to find elements, and :visible is not a valid CSS selector.

Instead, you could go two ways:

  1. Get all elements with a class of .form_error, then run isVisible() on them and filter the hidden ones out
  2. Use a custom execute function to run JavaScript on the page to check for visibility of elements. Something similar to this answer.

Upvotes: 2

Related Questions