- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to submit a form in Selenium webdriver if submit button can't be identified?
We can submit a form in Selenium webdriver even if the submit button cannot be identified. This can be achieved by locating any element within the form tag and the applying submit method on it. A form in the html code is identified by the <form> tag.
Let us investigate the html code of element with in a form tag −
In the above example, we shall try to submit the form with the help of the Email or Password field and not by clicking on the Sign in button.
Syntax
driver.findElement(By.className("input__input")).sendKeys("96968547"); driver.findElement(By.className("session_password")).sendKeys("test123"); driver.findElement(By.className("session_password")).submit();
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class SubmitFrm{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("https://www.linkedin.com/"); // identify element within form WebElement m=driver.findElement(By.id("session_key")); m.sendKeys("96968547"); WebElement n=driver.findElement(By.id("session_password")); n.sendKeys("test12"); //submit form n.submit(); Thread.sleep(1000); System.out.println("Page title: " + driver.getTitle()); driver.close(); } }
Output
- Related Articles
- How to submit a form in Selenium?
- Selenium Webdriver submit() vs click().
- Can I submit form with multiple submit buttons using jQuery?
- JavaScript Create Submit button for form submission and another button to clear input
- Display form values after clicking Submit button using event.preventdefault() - jQuery?
- How to use the submit button in HTML forms?
- How to enable and disable submit button using jQuery?
- How to submit a form using jQuery click event?
- How to call a JavaScript function on submit form?
- How to link a submit button to another webpage using HTML?
- How can I use multiple submit buttons in an HTML form?
- How to submit an HTML form using JavaScript?
- HTML DOM Form submit() method
- HTML DOM Input Submit form property
- How to add a Submit button after the end of the tableview using Swift?

Advertisements