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
Bug in android when finding elements in the xpath #677
Comments
I think the bug is because you're using findElements rather than findElement. findElements always returns an array even if there's just one element. |
Hi. In this case nothing is returned. Just an err |
Then that means appium couldn't find the element with that xpath selector. |
Right that is what i am trying to show what the bug is. The appium inspector shows what the xpath is but when using it I get an err |
@penguinho any chance the inspector is wrong about this android xpath? it looks way long and unwieldy to me. FWIW, I would never want to put an XPath like this in an actual test. It's much more maintainable to get a handle on it by content-description if you can have the devs add it. |
so, the long and unwieldy part of it is probably correct (which is why my team is using content-desc on everything for android, or relative xpath from an element with content-desc) I think the problem may be with the shorthand, bootstrap noticed that some of the elements like webview don't derive from android widget, so I think our xpath code assumes everything derives from android.widget |
I have been struggling with selecting elements using XPaths in Appium. In my experience, running find_elements_by_xpath('/frame[1]') and find_elements_by_xpath('/frame[100000]') returns the same number of elements. Isn't this true that '/frame[1]' means the first FrameLayout child of the root element and therefore it should only return one element at most? |
xpath in Appium has a number of limitations and open bugs. There are better On Mon, Jul 29, 2013 at 9:40 AM, Payman Delshad notifications@github.comwrote:
|
Here's my XML source: https://gist.github.com/paymand/6104530 and I'm trying to select the browser's tab container: <node index="2" text="" class="android.widget.FrameLayout" package="com.opera.browser" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,218][720,729]" /> (Adding a content-desc is not possible, since content-desc is also used for accessibility services like TalkBack and we'd like to add it only when it makes sense.) |
Have you tried finding all elements of that type and then selecting the find_elements(:tag_name, 'frame')[0] On Mon, Jul 29, 2013 at 10:15 AM, Payman Delshad
|
That does not work in our app, since we load layout files in runtime which means len(opera.driver.find_elements_by_tag_name('frame')) returns different numbers depending on which parts of the app have been visited. |
When the XPath bugs are fixed then that's probably the best option. On Mon, Jul 29, 2013 at 10:49 AM, Payman Delshad
|
Support for resource id is definitely awesome! You are referring to https://developer.android.com/tools/help/uiautomator/UiSelector.html#resourceId(java.lang.String), right? Hope we get the Appium support for the new features soon... |
On Mon, Jul 29, 2013 at 11:21 AM, Payman Delshad
Yes. I'll be adding Appium support soon. |
Fixed in appium 1.0. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Noticed that I can get the text by:
findElementsByXPath("//text[1]")
but would see duplicates/triplicates when doing this
findElementsByXPath("//linear[2]/text[1]")
Was expecting to get lesser data since I am specifically asking for the linear[2] path.
Also if I use what the inspector shows, I get an error as well.
And this is the xpath as shown on the inspector:
content-desc:
class: android.widget.LinearLayout
text: close
index: 1
enabled: true
clickable: false
xpath: //linear[1]/window[1]/linear[1]/window[1]/viewflipper[1]/linear[1]/list[1]/linear[7]/linear[1]/linear[1]/linear[2]/text[1]
The text was updated successfully, but these errors were encountered: