I already used this:
WebElement switch1 = driver1.findElement(By.id("com.android.settings:id/switch_widget")); if (switch1.isEnabled()) { System.out.println("enable"); } else{switch1.click(); }
but its not working.
use getAtribute("checked"), it will return string true or false.
where I have to use this attribute...You mean like this-if(switch1.getAttribute("checked").isEmpty()){}
As in switch1.getAttribute("checked") == "true"
switch1.getAttribute("checked") == "true"
thanks bro, its working.if (switch1.getAttribute("checked").equals("true")) { System.out.println("enable"); } else{switch1.click(); }
You can use getText with switchIf switch1.getText()=="OFF/ON"