I am trying to find an element in the else block, if the condition in the if block doesn't work.
try
{
if(Driver.driver.findElement(By.xpath("//div[@id='Tpay_success']")).isDisplayed())
{
System.out.println("Payment is successful");
Reporter.log("Payment is successful");
}
else
{
Thread.sleep(2000);
{
if(Driver.driver.findElement(By.id("pay_decline")).isEnabled())
{
System.out.println("pay declined");
action.moveToElement(By.id("pay_decline")).isEnabled()).click().perform();
Reporter.log("PAYMENT DECLINED!!");
}
}
catch(ExceptionInInitializerError ex)
{
System.out.println(ex);
}
}
I am getting an error saying:
Unable to locate element: {"method":"xpath","selector":"//div[@id='Tpay_succes']"}
I want the else block to be executed if the if block doesn't get executed. Any suggestions are welcome. Thanks.
elseand in front ofifif, and in general closing is not matching opening, neither is indentation