Reputation: 7
I am testing a website where I have to submit the form. I entered the username, password. Clicked Submit. But even though the form is submitted, I getting the following error message for submit:
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"name","selector":"submit"}
code: driver.findElement(By.name("submit"));
I wanted to know why this error occurs.
Upvotes: 0
Views: 940
Reputation: 29062
I wanted to know why this error occurs.
The error is occurring because there is no element on the page with the name
attribute with the value submit
.
My educated guess, is that you are trying to find the submit button, and getting confused with the By.name
By.name
will, as @Subh stated, find an element by the name. e.g: <input type="submit" name="submit" value="Submit" />
Give this a try:
driver.findElement(By.cssSelector("[type='submit']")
// careful though, if there are more than one of these, then you need to increase the specificity
Upvotes: 1