I tried only on android, version 9, in the emulator.
The following search works, and the id is clearly present in the appium-desktop session window.
await driver.$(‘id=android:id/button1’);
But it does not work when I try to only find a part, containing button1. Either adb says it cannot compile, or it says element not found.
await driver.$('//*[contains(@id, "button1")]');
await driver.$('//[contains(@id, "button1")]');
await driver.$('//[contains(@id, \'button1\')]');
await driver.$('//*[contains(@id, \'button1\')]');
By the way, webdriverio detects that it is an xpath if the locator starts with a slash.
I checked the doc // takes the active element. SO maybe just a slash should be used? WHy use one slash or 2?
I never could use xpath. Only //* works. The long xpath given in appium desktop also works.
Here it is:
/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.support.v7.widget.LinearLayoutCompat/android.widget.ScrollView/android.widget.LinearLayout/android.widget.Button
I also added a await sleep before to be sure the button is visible before the search is done. But the long xpath works so it should not be a problem of non present element.
Anyone knows? Thanks!
I also copy all the data on it in the inspector:
Find By | Selector |
---|---|
id | android:id/button1 |
xpath | /hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.support.v7.widget.LinearLayoutCompat/android.widget.ScrollView/android.widget.LinearLayout/android.widget.Button |
Attribute | Value |
---|---|
elementId | c1e5de65-e694-4db5-bd0a-9cefceb039b3 |
index | 0 |
package | com.generosales.striker |
class | android.widget.Button |
text | OK |
resource-id | android:id/button1 |
checkable | false |
checked | false |
clickable | true |
enabled | true |
focusable | true |
focused | false |
long-clickable | false |
password | false |
scrollable | false |
selected | false |
bounds | [777,940][969,1084] |
displayed | true |