When we look at the try and catch we can see that we normally use catch (Exception e); but in the case of Webdriver we will have to use catch (Throwable e).
So try to use this:
public WebElement getPasswordField() {
public WebElement getPasswordField() {
SmallLoginLocators slogin = PageFactory.initElements(wd, SmallLoginLocators.class);
WebElement password;
try {
password = slogin.passwordField1;
} catch (**Throwable** e) {
password = slogin.passwordField2;
}
return password;
}
}
This resolved my issue.