I am running into a strange problem with webdriverio/appium when trying to test an iOS app. The app has a WebView with a button labeled "Refresh". When I try to test for this button, I get a "not displayed" error (see code below).
it('should have the Refresh button', () => {
WebViewScreen.waitForWebsiteLoaded();
// Verify that Refresh button is displayed
WebViewScreen.switchToContext(CONTEXT_REF.WEBVIEW);
const button = $('button=Refresh');
expect(button).toBeDisplayed();
WebViewScreen.switchToContext(CONTEXT_REF.NATIVE);
});
Note that I am switching context to WEBVIEW before testing for the button. Looking at Appium logs, the request to find the button ($('button=Refresh')
) is returning a 404. Tried a different selector: ['button[data-test="refresh-button"]']
, but no go. I even put a browser.debug() and queried in the REPL - still 404 - although I can physically see the button on the screen!
I know that my webdriverio/appium setup is good because the exact same code works for another iOS screen with a WebView and a button - the only difference is the button name.
I have also ruled out the possibility that my selector is incorrect by going to the standalone webpage and testing for that button - no errors in this case! Here's the standalone web page code - only difference is no context switching calls:
it('should have the Refresh button', () => {
browser.url('https://example.site.com/');
// Verify that Refresh button is displayed
const button = $('button=Refresh')
expect(button).toBeDisplayed();
});
Any ideas on how to debug this? Are there any nuances about switching to WEBVIEW context that I am missing?