Submitting Form Using submit() Method Of Selenium WebDriver

You volition detect many forms In whatsoever software spider web application similar Contact Us form, New User Registration Form, Inquiry Form, LogIn Form etc.. Supposing yous are testing ane software website where yous get got to create Login shape submission bear witness illustration In selenium webdriver hence how volition yous create It? Simplest means Is described In THIS POST. If yous will see In that illustration post, nosotros get got used .click() method to click on Login button.

Selenium Webdriver software testing tool has ane particular method to submit whatsoever form in addition to that method advert Is submit(). submit() method industrial plant same equally clicking on submit button.


When to role .click() method
You tin role .click() method to click on whatsoever push of software spider web application. Means element's type = "button" or type = "submit", .click() method volition industrial plant for both.

When to role .submit() method
If yous volition expect at firebug thought for whatsoever form's submit push hence e'er It's type volition hold upwards "submit" equally shown In bellow given Image. In this case, .submit() method Is really proficient choice of .click() method.


Final Notes :
1. If whatsoever shape has submit push which has type = "button" hence .submit() method volition non work.
2. If push Is non Inside <form> tag hence .submit() method volition non work.

Now permit us convey a expect at really uncomplicated illustration where I get got used .submit() method to submit shape on software spider web page. In bellow given example, I get got non used .click() method but used .submit() method alongside companionship advert field. Run bellow given illustration In eclipse alongside testng in addition to verify the result.
package Testng_Pack;  import java.util.concurrent.TimeUnit;  import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace shape Form_Submit {   WebDriver driver = novel FirefoxDriver();       @BeforeTest   populace void setup() throws Exception {           driver.manage().window().maximize();          driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);          driver.get(" ");    }      @AfterTest   populace void tearDown() throws Exception {     driver.quit();      }       @Test   populace void LogIn_Test(){    driver.findElement(By.xpath("//input[@name='FirstName']")).sendKeys("MyFName");    driver.findElement(By.xpath("//input[@name='LastName']")).sendKeys("MyLName");    driver.findElement(By.xpath("//input[@name='EmailID']")).sendKeys("My Email ID");    driver.findElement(By.xpath("//input[@name='MobNo']")).sendKeys("My Mob No.");    driver.findElement(By.xpath("//input[@name='Company']")).sendKeys("My Comp Name");    //To submit form.    //You tin role whatsoever other Input field's(First Name, Last Name etc.) xpath equally good In bellow given syntax.    driver.findElement(By.xpath("//input[@name='Company']")).submit();    String alrt = driver.switchTo().alert().getText();    driver.switchTo().alert().accept();    System.out.println(alrt);   } }

Above illustration volition but submit the shape in addition to holler back submission warning to print. So this means nosotros tin role webdriver's submit method to submit whatsoever form. You tin endeavor dissimilar shape for your improve understanding.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

 http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post