문제

I am using Appium for testing mobile application.When I use xpath it is working fine but I am not able to work on Ids for that app.

//This is working fine

remoteDriver.findElementByXPath("/linear[1]/window[2]/linear[1]/linear[1]/linear[2]/linear[1]/text[2]").click(); // Click on signIn button 

// This doesn't recognize the element

remoteDriver.findElementById("ButtonSignIn").click(); // Click on signIn button

If anybody has experience on appium using ids then please share your experience.

Thanks

도움이 되었습니까?

해결책

Using the Id is possible only for android API level 18 or above (Jelly Bean). If you use the uiautomatorviewer , then in Node Details you shall see "resource-id" which can be used easily to automate the app, but the same id will not work for android API level < 18. Work around is to use other element properties like - xpath,tagName,className etc. For more details use the link - https://github.com/appium/appium/blob/master/docs/finding-elements.md

다른 팁

Appium "id" correlates to the Android Resource Id, and can be accessed like this:

remoteDriver.findElementById("com.exampleCompany.appName:id/ButtonSignIn").click();

One issue I have run into using IDs with Appium is ListView. Because lists are created 'on the fly' in Android, each row actually has the same Android Resource Id, even though each row is filled with different content from the user's perspective.

If you find that your buttons are part of a ListView and that is why they cannot be accessed, you could get around this by dynamically setting the content descriptors for each row as it is created, and then referencing these through Appium using "find element by name."

Double check the ID being used. The ID shouldn't be "ButtonSignIn" but rather "com.company.app:id/ButtonSignIn".

The call should be:

remoteDriver.findElementById("com.company.app:id/ButtonSignIn").click();

Basically, if the layout.xml file specifies the ID for the button with android:id="@+id/ButtonSignIn" (and your app is com.company.app) then in your test you should use "com.company.app:id/ButtonSignIn" instead of "ButtonSignIn".

Also find by ID should work with Appium because it uses Selendroid, which supports it.

Instead of ids, I used FindElementsByClassName("abc.widget.EditText") (for example) or FindElement(By.Name("Continue")

The class names work great...if there is more than 1 on the page...just select the index value of the one you need. For example: textfields[1].Sendkeys("1234")

I have been using findElement(By.id("")) instead. For example:

remoteDriver.findElement(By.id("ButtonSignIn")).click();

It has been working well for me so far.

Use android uiautomatorviewer to get correct android element id.Click the link below:

Can we find element by ID in appium

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top