Webdriverio - Can I wait for an element to appear on android

I’m currently trying out the javascript clients for testing an android app.

With wd I found the function “waitForElementById” to wait until an element is available.

As the webdriverio client seems better documented and is used in the getting started example I would like to give it a chance. But basically without a stable way to wait until I can actually interact with elements I don’t see any way how to get ANY test done.

I would think something like:

  1. Click button
  2. assert new activity is opened
  3. Do something there: for example entering text to a field
  4. assert that text was entered

is an absolute basic test case for any application (web, android, ios,…) so I can’t believe it isn’t available.
But for that its vital to wait for the element of 1. and 3. to be loaded, else any attempt to locate that element would fail the test (because it just isn’t there yet)

So: How to wait for an element with webdriverio?

As a side question: Is there any decent documentation on the javascript clients in conjunction with appium? I’m guessing my way for at least 3 days now.

Okay, it seems my actual problem wasn’t about waiting but about my understanding of selectors in webdriverio, my apologies.

With client = await webdriverio.remote(caps);
I used element = client.findElement("id","<some resource id>");

I didn’t pay attention to the fact that whatever I was getting there, wasn’t an element in the form I need for the other webdriverio function.


let element = 
    await client.$('android=new UiSelector().resourceId("<some resource id>")');
await element.waitForDisplayed({ timeout: 30000 });
await element.click();

(Regarding my original question: now I can use waitForDisplayed())
This time I stumbled upon the solution on some site (in this case: https://www.browserstack.com/docs/app-automate/appium/getting-started/nodejs/webdriverio) and had again guess my way to something that doesn’t crash (and indeed worked).

I think I’m doing something fundamentally wrong, because I can’t find any good sources

I feel the same way. Did you ever find any good tutorials?

Like you, I’ve been guessing what to do. I found that Browserstack tutorial helpful. But I’m surprised at how hard it is to find other guides for using Webdriverio to test an Android app.

Hi @Ross1, welcome on board.
Good tutorials are hard to find, probably because everyone seems to think they know how to use this tool so they go and blog with titles like “Top 10 tips”, and get all the google hits, but actually don’t warn you how hard it is to use these tools. You gotta pay for good content, or you gotta do the time to learn abotu explicit an implicit waits. I prefer explicit, and I build my wrapper objects around explicit waits.

Mainly because if you use implicit waits, negative test cases become almost impossible to write. Out of box, that’s what 90% of users want, positive happy-path. And then they find they have to re-write all of their test code suddenly when they start negative test case writing.