If else on a text element

I am fairly new to coding and Appium so please forgive me if I’m missing information. I am desiring to go through a list of services, with n amount of services entered by the user, and checking if the service is complete or not. Once it checks all the services, ensuring they’re complete, the test moves on to the next tab.

I created a for loop that takes into account the number of services that exist and checks each service’s complete status. However, this status appears only as Text (Yes or no), is there a way to do an if else statement that checks against this text and decides whether or not to move on?

It looks like your app is missing Ids for the elements. Best practice would be first to get the developers to add Ids. Nevertheless, one approach here might be to use XPath to get all elements of type android.widget.Checkbox and then check each one for the text in your for loop. Note also that the checkbox has a “checked” attribute which in this case is set to false. Checking that for true or false may be a better approach than checking the text.

1 Like

Yeah I’ve been hounding the dev for ID’s on the elements but I understand he’s got a huge work load so I am trying to make due with what’s available. I like your idea of using the checked attribute. I have this IF ELSE IF within my loop so far but it gives me a 404 when it gets to the first if statement, not sure if I am writing it wrong?

if (driver.findElement(By.xpath("//android.widget.CheckBox[@checked=‘Yes’]")).isSelected())
{
continue;
}
else if(driver.findElement(By.xpath("//android.widget.CheckBox[@checked=‘No’]")).isSelected())
{
//clicking on edit button of Service (i) to complete service
driver.findElement(By.xpath("//android.widget.Button[@resource-id=‘mainCard_p_edit_btn’]")).click();
Thread.sleep(1000);
//add Tech
driver.findElement(By.xpath("//android.view.TextView[@text=‘Technician:’]")).click();
Thread.sleep(1000);
}