So I'm trying to test out the first name section of this link (https://softwaretestinggn8fe.herokuapp.com/) using selenium in java to show that the error message "First Name can only contain characters." will be shown when I type "545" into the first name section of the website. However my test fails and this is the error I get:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"*[name='submit']"}
(Session info: chrome=86.0.4240.198)
Does anyone know how to solve this issue?
import org.testng.AssertJUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class WebTesting {
@Test
public void test1() {
System.setProperty("webdriver.chrome.driver", "C:/Users/mtecl/Desktop/Drivers/chromedriver.exe"); // configure path to the driver
WebDriver driver = new ChromeDriver();
driver.get("https://softwaretestinggn8fe.herokuapp.com/");
//Username
WebElement testUsername = driver.findElement(By.id("firstname")); //id: first name
testUsername.sendKeys("545");
//Button
driver.findElement(By.name("submit")).click();
String expected = "First Name can only contain characters.";
String actual = driver.findElement(By.xpath("html/body/div/main/div[2]/form/div[1]/span")).getText();
Assert.assertEquals(expected, actual);
}
}