I tried to use xpath for custom attribute provided by developers but getting no element found exception.
[HTTP] --> POST /wd/session/5fcb27d1-ab07-4d9b-b06f-cb4d006391e3/element
[HTTP] {"using":"xpath","value":"//input[@data-autoid='AC_NAME_ctrl']"}
[debug] [W3C (5fcb27d1)] Calling AppiumDriver.findElement() with args: ["xpath","//input[@data-autoid='AC_NAME_ctrl']","5fcb27d1-ab07-4d9b-b06f-cb4d006391e3"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
[debug] [BaseDriver] Waiting up to 10000 ms for condition
[debug] [WD Proxy] Matched '/element' to command name 'findElement'
[debug] [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8201/wd/hub/session/bb01926e-16fe-426e-881c-d1b4c689bc8e/element] with body: {"strategy":"xpath","selector":"//input[@data-autoid='AC_NAME_ctrl']","context":"","multiple":false}
[WD Proxy] Got response with status 404: {"sessionId":"bb01926e-16fe-426e-881c-d1b4c689bc8e","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.findElement(FindElement.java:90)\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:67)\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.AbstractChannelHandlerCont...
Code used:
WebElement f1 = driver.findElement(By.xpath("//input[@data-autoid='AC_NAME_ctrl']"));
f1.sendKeys("Rahul");
data-autoid is custom attribute with value 'AC_NAME_ctrl' Any help in this direction will be helpful.
CodePudding user response:
For hybrid apps, Appium has to know whether you want to automate the native aspects of the app or the web views.
Switch to web-context before interaction with web views elements.
driver.context("WEBVIEW_1");
and then
WebElement f1 = driver.findElement(By.xpath("//input[@data-autoid='AC_NAME_ctrl']"));
f1.sendKeys("Rahul");
do not forget to switch back to native.
driver.context("NATIVE_APP");
This will print all the available contexts:
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
}
Reference
https://appium.io/docs/en/writing-running-appium/web/hybrid/
CodePudding user response:
If i get it right , you wanna create a locator based on the customer input ?