NoSuchElementError for Android Appium locators

389 views Asked by At

I am using Appium 1.22.3 and webdriverIO5 for Android mobile automation The DOM for the element I am trying to click on is as below:

<android.widget.Button content-desc="Sign in">

I have used different combinations of locators as below:

await $('android.widget.Button');
driver.elementsByAccessibilityId('Sign in');
$('Sign in');
$('id=Sign in')
findElementByAccessibilityId("Sign in"); 
dr.findElementByAccessibilityId("Sign in")

However none of these xpaths work and I get error as below:

2022-09-04 12:35:01:866 - [HTTP] {"using":"class name","value":"android.widget.Button"}
2022-09-04 12:35:01:869 - [debug] [W3C (b124862d)] Calling AppiumDriver.findElement() with args: ["class name","android.widget.Button","b124862d-91b8-4b4a-9d50-bba5b9b912f4"]
2022-09-04 12:35:01:869 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
2022-09-04 12:35:01:869 - [debug] [BaseDriver] Waiting up to 0 ms for condition
2022-09-04 12:35:01:869 - [debug] [WD Proxy] Matched '/element' to command name 'findElement'
2022-09-04 12:35:01:869 - [debug] [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8200/wd/hub/session/0900bfc4-1ae4-4c76-895d-3203dca78bcc/element] with body: {"strategy":"class name","selector":"android.widget.Button","context":"","multiple":false}
2022-09-04 12:35:02:441 - [WD Proxy] Got response with status 404: {"sessionId":"0900bfc4-1ae4-4c76-895d-3203dca78bcc","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:70)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:266)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:260)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
2022-09-04 12:35:02:441 - [debug] [W3C] Matched W3C error code 'no such element' to NoSuchElementError
2022-09-04 12:35:02:454 - [debug] [W3C (b124862d)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.

Appreciate any help on how to identify the correct locator here

1

There are 1 answers

0
rohini dingankar On

Thanks. I was able to use let el = await $('//android.widget.Button[@content-desc="Sign in"]'); successfully finally!