lundi 5 octobre 2020

If else breaking on first if statement when element not found

Good Morning Everyone, I tried searching for my answer but could not find anything.

I am trying to run an If else that checks if an element is visible if it is not then move to the next if else. When the element is not found for the first If statement the test fails instead of proceeding to the following if else check.

    if (overview.allowLocationButton.isDisplayed()) {
        overview.allowLocationButton.click();
    } else if (overview.allowLocationAllTimeButton.isDisplayed()) {
        overview.allowLocationAllTimeButton.click();
    } else if (overview.allowLocationForegroundButton.isDisplayed()) {
        overview.allowLocationForegroundButton.click();
    } else {
        System.out.println("Could not find any of the buttons");
    }

What am I missing here? Any help would be greatly appreciated.

EDIT: More information, I am testing multiple versions of android for my application and location services need to be allowed after signing in to the application. allowLocationButton, allowLoactionAllTimeButton, and allowLocationForegroundButton map to this button depending on the version of android. In the case of this test I am expecting the first statement to return false and the process the following else if statement. It breaks on finding no element for the first if check overview.allowLocationButton.isDisplayed() and does not continue in to first else if statement.

Aucun commentaire:

Enregistrer un commentaire