I create a function to verify element on android using try and catch and when the element is not present my expectation it will print the variable name, I've tried this syntax but until now it still prints the value of the variable.
public void verifyEl(String element) {
try {
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElementByXPath(element);
}catch (NoSuchElementException e) {
Assert.fail("Element "+element+" is not found");
}
Assert.assertTrue((driver.findElementByXPath(element)).isDisplayed());
}
String Email_form = "//android.view.View/android.widget.EditText[1]";
public void verifyLoginPage() {
mainFunc.verifyEl(Email_form);
}
Actual result:
Element //android.view.View/android.widget.EditText[1] is not found
Expected result:
Element Email_form is not found