Appium: Android Resource ID: translates to what in their selenium integration?

北城余情 提交于 2019-12-21 17:22:49

问题


So for example I have:

wd.findElement.By(name("searchBttn"));

the resource-id in the ui xml screen cap is com.aut.android:id/searchBttn

and Appium can't find the item. I have tried with ID and Name. Is there something else here i could try is there a direct line for line correlation list somewhere that i am missing?


回答1:


I could not find much documentation on this topic. You can refer this link - https://groups.google.com/forum/#!topic/appium-discuss/LcjbXPFX1N0




回答2:


You can find an Android item in Appium by Resource ID, but you have to specify the entire package name along with the resource id:

wd.findElement.By(id("com.aut.android:id/searchBttn"));



回答3:


You can fetch element by few more way other than name or id is not available

Can find element find by using resource-id like below example:

driver.findElement(By.xpath("//*[@resource-id='login']")).click();

driver.findElement(By.xpath("//*[@id='cash']")).click();

Here: com.android.calculator2:id/digit5 is complete resource id and can use like this:

driver.findElement(By.id("com.android.calculator2:id/digit5")).click();

Can find by class name:

driver.findElement(By.className("android.widget.Button")).click();



回答4:


At least name works for me. I'm trying to find out how it works for ID, but you can look at the following.

Example: If the button text is set to "testbtn", then you can access it from Appium with the following command:

driver.findElement(By.name("testbtn")).click();

This works for me, try it.

EDIT: As one of the Appium devs stated here, it currently seems to be not possible to access elements by ID on Android.

EDIT2: This feature is now implemented! As I found out, you can now access elements from Android by ID using selendroid (it seems to be a sub part of Appium).

In your test class you need to specify capabilities.setCapability("device", "selendroid"); when setting up instead of capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");

Now you can just access a button with

driver.findElement(By.id("testbtn")).click();

You can find the official documentation from Selendroid here




回答5:


I had the same problem in python where I couldn't find the elements that had the id attribute even though I could see them in the appium inspector. Some of the apps have multiple contexts that the driver can handle like NATIVE_APP & WEB_VIEW so I had to switch the context of the driver to WEB_VIEW so it could find the elements with the driver.find_elements_by_id("")(python syntax)

Documentation on how to switch contexts with code examples - http://appium.io/docs/en/writing-running-appium/web/hybrid/index.html



来源:https://stackoverflow.com/questions/18362400/appium-android-resource-id-translates-to-what-in-their-selenium-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!