I’m building out an automation test with Selenium and when I attempt to use an if/else statement with .isDisplayed I will always get this response. “no such element: Unable to locate element:” The webelement it is checking for is not displayed which should direct it to complete the else statement, but it ends the test. How would I write a work around?
<code>@Step("Click the Open IRA Account")
public PortfolioHomePage clickOpenIRAAccount(){
waitForElementToAppear(signOutBtn);
if (openAccountBtn.isDisplayed()) {
waitForElementToAppear(openAccountBtn);
openAccountBtn.click();
} else {
waitForElementToAppear(finishMyApplicationButton);
finishMyApplicationButton.click();
}
return this;
}
</code>
<code>@Step("Click the Open IRA Account")
public PortfolioHomePage clickOpenIRAAccount(){
waitForElementToAppear(signOutBtn);
if (openAccountBtn.isDisplayed()) {
waitForElementToAppear(openAccountBtn);
openAccountBtn.click();
} else {
waitForElementToAppear(finishMyApplicationButton);
finishMyApplicationButton.click();
}
return this;
}
</code>
@Step("Click the Open IRA Account")
public PortfolioHomePage clickOpenIRAAccount(){
waitForElementToAppear(signOutBtn);
if (openAccountBtn.isDisplayed()) {
waitForElementToAppear(openAccountBtn);
openAccountBtn.click();
} else {
waitForElementToAppear(finishMyApplicationButton);
finishMyApplicationButton.click();
}
return this;
}
I have tried {}Catch(Execeptions e) but that didn’t help.
New contributor
Daniel Bennett is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.