We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
Submitting forms the modern Selenium way using click() instead of submit().
The submit() command was originally designed to submit an HTML <form> in a simple, traditional way. In modern web apps, however, clicking the submit button is usually the better and more reliable choice.
element.submit() → Legacy methodbutton.click() → Modern, recommended approachclick() on it. Treat submit() as a legacy escape hatch.Form ID: lesson6-form
Button ID: submit-btn
Type a search term and click "Search". The form turns purple to indicate a successful submission.
12345678WebElement searchBox = driver.findElement(By.id("lesson6-search"));
searchBox.clear();
searchBox.sendKeys("Selenium testing");
WebElement submitButton = driver.findElement(By.id("submit-btn"));
submitButton.click();
driver.quit();"Selenium testing" into the search field.id.Prefer click() on the submit button instead of submit() on the form. It behaves like a real user and is far more reliable in modern web apps.
Treat submit() as a legacy escape hatch. If you’re testing older, simple forms without JavaScript, it can still work.