I always have issues with if statements in selenium. Most of the time they do the opposite of what they are supposed to do.
I have deliberately typed an incorrect email address so the payment will fail. Thee Oops! is displayed on the webpage which is the correct response however my test comes back fail. The xpath is correct as it passes when I type the correct email in.
Please can someone take a look and advise me where I am going wrong.
@Test(dependsOnMethods = { "WithdrawalButtonOnNavBar" })
public void WithdrawWinnings() throws InterruptedException {
Thread.sleep(500);
driver.findElement(By.cssSelector("input[name='email']")).sendKeys(skrillAccount);
Thread.sleep(500);
driver.findElement(By.xpath("//p[contains(text(),'Continue')]")).click();
Thread.sleep(500);
driver.findElement(By.cssSelector("input[name='amount']")).sendKeys("2");
Thread.sleep(500);
driver.findElement(By.xpath("//*[@id=\"__next\"]/div/div[1]/div[2]/div/div[3]/div/div/div")).click();
Thread.sleep(5000);
WebElement Success = driver.findElement(By.xpath("//p[contains(text(),'Success!')]"));
WebElement Oops = driver.findElement(By.xpath("//p[contains(text(),'Oops!')]"));
if (Success.isDisplayed()) {
System.out.println("Payment was successful");
} else if(Oops.isDisplayed()) {
System.out.println("Payment was unsuccessful");
}
;
}
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//p[contains(text(),'Success!')]"} (Session info: chrome=90.0.4430.85) For documentation on this error, please visit: https://selenium.dev/exceptions/#no_such_element
Aucun commentaire:
Enregistrer un commentaire