1

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.

enter image description here

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.

enter image description here

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

Pankaj Nimgade
  • 4,529
  • 3
  • 20
  • 30
  • would need to understand the POM you are following and how is the widget accessed by your application. There is very less info in the question in that regard. – Naman Sep 14 '16 at 08:04

3 Answers3

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

AnswerDroid
  • 1,873
  • 2
  • 33
  • 52
1

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.

TinyTimZamboni
  • 5,275
  • 3
  • 28
  • 24
0

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

barbudito
  • 548
  • 1
  • 6
  • 16