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

限于喜欢 提交于 2019-11-27 16:27:17

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

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.

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

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