Access toggle button in Android settings using appium whlie client is written in groovy and java

喜你入骨 提交于 2019-11-26 18:38:03

问题


It's not a duplicate.

I am writing automation in Appium. I am fairly new to automation concept and Appium it self. I am using java-client.

I have a scenario in which my android app for which I am writing automation, has to take android permission. My application navigates to following setting page of Android Settings as shown below.

To automate clicks on this page I have created a Page Object which would represent this screen. in this scenario I am only interested in toggling the Switch and to learn how to get it's state.

I could get resource id for the UI Automator Viewer something like this.

So my initialization is something like this to access the switch Widget.

SwitchID { $("#switchWidget") }

Apparently, When i run the feature file, Appium is not able to find this switch widget. But I can automate other widget inside the application I am working on. but I can't get anything on this setting screen of android.

Any help would be highly regarded. Thanks


回答1:


You can access any visible component on UI. Be it buttons/ switches or whatever.
There are several ways to access an element using Appium/ Selenium driver - By name/ id/ xpath, etc.
Use UIAutomator to capture that visible element's id/name/ content desc and you're done!
In your case, as I can see in UIAutomator screenshot - you are getting both id and name. So you can use any of them to click your desired element.
(You can refer to your relevant groovy/java syntax from Appium)
http://appium.io/introduction.html




回答2:


Using the java-client I would get the switch by class name. Something like this: driver.findElement(By.className("android.widget.Switch"))

Not sure about the groovy client, but it's probably similar.




回答3:


What if the switch is checked already? If you tap you will disable it...

Try:

driver.find_element_by_xpath("//android.widget.Switch[@resource-id='android:id/switchWidget' and @checkable='true']")

This will only get your element when is checkable



来源:https://stackoverflow.com/questions/39484982/access-toggle-button-in-android-settings-using-appium-whlie-client-is-written-in

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