-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Appium cannot find element by ID, but can by XPATH #509
Comments
@ws-aweaver You can see appium log on terminal by adding
|
@ki4070ma Thank you so much for this! I've attached the full logs below, but I saw a few possible candidates for the issue:
Maybe it is unable to analyze the apk to get all of the ids?
It may be taking cached data from an old version of the application that did not have the IDs (doubtful, as I've verified the ID exists in Appium Studio) Full logs: Moved to https://gist.github.com/ki4070ma/7740f16c776c8b2e5540911c385c7559 |
I am using the ID value, not the accessibility id. I've verified the ID is correct using Appium Studio, which has similar functionality to the Appium Desktop you showed. |
Is below result expected(as design)? Notes
Results$python SampleAndroidTest_apidemo.py
0
12
0 Sample codes#!/usr/bin/python
# -*- coding: utf-8 -*-
from appium import webdriver
caps = {
'platformName': "Android",
'deviceName': "Android Emulator",
'appPackage': "io.appium.android.apis",
'appActivity': ".ApiDemos",
'automationName': "uiautomator2",
}
if __name__ == '__main__':
driver = webdriver.Remote('http://localhost:4723/wd/hub', caps)
# Found elements: 0
els = driver.find_elements_by_id("id/text1")
print(len(els))
# Found elements: 12
els = driver.find_elements_by_id("android:id/text1")
print(len(els))
# Found elements: 0
els = driver.find_elements_by_id("io.appium.android.apis:id/text1")
print(len(els))
driver.quit() |
Yes. It depends on the app under test. You can find elements by The behaviour is not Appium specific. |
@ws-aweaver As #509 (comment), it might be necessary to update used id. |
I am trying to replicate this behavior in my code. I am using this function to wait for the element to appear:
My understanding is
I also tried I also tried downloading Appium Desktop just to be sure. It looks like the application I already have and was previously using to manually set up the Appium service. However, Mac is being difficult and says the app can't be opened with no explanation why. The version of Appium Desktop I already have doesn't have any element inspection services that I know of. |
Update: I tried yesterday to demonstrate to somebody that XPATH works. It is no longer working. I also confirmed that I am in the correct context ("NATIVE_APP"). I am unsure what this means, as I have not changed the code in the application or the automation suite. EDIT: XPATH is working correctly with UIAutomator2. It breaks on UIAutomator1. ID does not work with either. I also tried a cheap workaround by using XPATH to find an element with the ID It looks like I need to find a method that looks by resource ID. I tried all of the methods below and they do not find the element: I have the app set the ID programatically, but not the resource ID. The resource ID is the same as the regular ID, so for now I am able to progress with the ugly workaround. I would like to do this properly, though. |
@ki4070ma How do I get resource ID properly in Appium Python Client? I didn't find a method for it. I used the ugly workaround in my above comment for now, and it looks like there is a serious performance issue. My test is taking around 15 minutes to execute. The old suite of 12 tests took around 20 minutes. I'd really like to get the execution time much lower. |
@ws-cdavis just wondering if you ever found a resolution for this? I'm afraid I'm not proficient in python like you clearly are so I'm utilising the appiumlibrary that's part of robot framework, however, I too have a problem that if I express as id=X it fails to find the element. If I express that same element as //*[@resource-id="X"] it works flawlessly. |
Hey Did you find the way to find elements by id? |
Basically |
Try specifying "chromeOptions": {"w3c": False} in your dc. |
I am facing a similar issue too. Does anyone know why? potential fix ID directly? |
It is via findObject by Android directly https://github.com/appium/appium-uiautomator2-server/blob/cef81e2a9755e103ff5a6fb488938a14ff8a7016/app/src/main/java/io/appium/uiautomator2/handler/FindElement.java#L82 or XPath info cached by Appium/UIA2 server from AccessibilityNodeInfo by Android (since Android does not support XPath natively). The difference might cause it. |
^ This could also be an issue with accessibility identifiers naming (app identifier prefix is missing). Then appium/appium#15138 (comment) could be used as a workaround. |
I'm having the same issue maybe:
I've attached two screenshots, the second one is to show that selecting with id: "org.plantnet:id/action_bar_root" does work. but the first one with id: "org.plantnet:id/bottomtabexplorer" or simply "bottomtabexplorer" does not work. Here is my capabilities:
|
it's crazy but the only thing that worked for me was to use
I had updated Appium globally, tried to change the capabilities to be more accurate and everything but this solve the issue right away. |
Yes I cannot get the accessibility ID's to work either and like @HugoGresse I can only get it to find the elements by the xpath in appium with webdriver i/o latest versions. This is a react native app that I'm working with: DC's are capabilities: { I'm using an android nexus 6p with android 12 I have tried everything suggested. This is blocking for me as one of the elements is off the screen and the scrolltoView is not implemented yet and I can't find elements that are not visible with xpaths. Any suggestions? |
@mtaylor-evidation if you're dealing with android you have a different problem--elements that are not on screen do not exist (android doesn't have any concept of an element being available/existing if it's not actually on screen). so you'll never be able to find it. the best practice for the uiautomator2 driver is to do what a user would do--perform a scroll and then check if the element is on screen, and repeat. |
Totally agree,
Unfortunately, ScrollIntoView in webdriverio does appear to work. However,
I know there may be other ways to scroll with appium, just trying to find
the best way to do it. :)
|
I don't know what "scroll into view" is. sounds like maybe it's a webdriverio thing. it's not an appium command. it's unclear to me how webdriverio implements it under the hood. it'd be better to do the correct appium thing, which is to use the actions api to construct a finger movement that will perform a scroll. |
I've made something like this to scroll the view down. It's not perfect but it works ~ok
|
So amazed by this community. Although the solution proposed won't work for me (JavaScript is what I'm using) but I've really gleaning off of all of your knowledge. I appreciate your responses today I'll be heads down trying to figure it out for JavaScript maybe even consider branching out and using native webdriver |
I am also facing issue to find the locator, I have mentioned the code below package Mobile_Testing; import java.io.File; import org.openqa.selenium.By; import io.appium.java_client.android.AndroidDriver; public class First_TestCase {
}} I have also tried |
Please help me |
try replacing your Xpath to look like this: "//*[@resource-id='com.bank.standard:id/urs_nm']" |
Hi thanks for the reply I have tried but not working. |
The problem
I've been working on dual Appium/Selenium test suite for a web page and mobile app. When using Appium, it is unable to find the element by ID. If I change it to use XPATH, it works as expected, then fails to find the next element by ID. This may not sound like a problem, but other elements in the app are not easily distinguished by XPATH values.
This test suite worked previously with manual app install and the Appium Service running on Mac. I've since tried to automate the process to install the application and run Appium Service programmatically. I am wondering if the way I've set this up is causing it not to detect elements by ID.
I know for certain the ID is correct. It works for the Selenium + web page combination, and I've tried digging into the app with Appium Studio. It displays the ID correctly in the app, and copy pasting the ID into my code doesn't change anything.
Environment
Link to Appium logs
Unfortunately, it doesn't look like the AppiumService in Python creates logs. If it does, I'll attach them when I find them or somebody tells me where they are
Code To Reproduce Issue [ Good To Have ]
Code below (redesign_tags and redesign_locators contain some sensitive info, but they work as intended in the Selenium flow):
The text was updated successfully, but these errors were encountered: