How to use if-else condition for this switch using appium java

I already used this:

WebElement switch1 = driver1.findElement(""));
	if (switch1.isEnabled()) {
	}	else{;

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-

As in switch1.getAttribute("checked") == "true"

1 Like

thanks bro, its working.
if (switch1.getAttribute(“checked”).equals(“true”)) {
} else{;

You can use getText with switch
If switch1.getText()==“OFF/ON”

im using this function below but actually appium still perform both conditions for example if the element is displayed it will perform first part in the if() and then the part of catch ()

and if the element is not displayed it will perform only the part in catch

and this not what i want, i want if the element is displayed do this and end the test

and if the element is not displayed do this and end the test
public void Verify_user_can_add_and_remove_song() {;;;
try {
if (element.isDisplayed()) {
System.out.println(“song is displayed in the playlist”);;
//performing long press (press and hold)
TouchAction action = new TouchAction(driver);
Assert.assertNotEquals(element.isDisplayed(), false);

    } catch(NoSuchElementException e){
                System.out.println("element is not displayed in the playlist");
                //conditional wait until presence of an element
                new WebDriverWait(driver, 15).until(ExpectedConditions.presenceOfElementLocated(""))).click();
                Assert.assertEquals(elemnet.getText(), " text (Original Mix)");