What is the most effective way to fill out information on a web form?

Take a standard web page with lots of text fields, crashes, etc. What is the most efficient way in webdriver to populate values, and then verify that the values ​​are entered correctly.

+4
source share
2 answers

You only need to check the correctness of the input of values ​​if there is any JavaScript check or other magic in your input fields. You do not want to check the correct operation of webdriver / selenium.

There are various ways, depending on whether you want to use webdriver or selenium. Here is a potpourri of what I use.

Assert.assertEquals("input field must be empty", "", selenium.getValue("name=model.query")); driver.findElement(By.name("model.query")).sendKeys("Testinput"); //here you have to wait for javascript to finish. Eg wait for a css Class or id to appear Assert.assertEquals("Testinput", selenium.getValue("name=model.query")); 

Only with webdriver:

 WebElement inputElement = driver.findElement(By.id("input_field_1")); inputElement.clear(); inputElement.sendKeys("12"); //here you have to wait for javascript to finish. Eg wait for a css Class or id to appear Assert.assertEquals("12", inputElement.getAttribute("value")); 
+7
source

We hope that the results of filling out the form are visible to the user in some way. So you can think along these lines of BDD-esque:

 When I create a new movie Then I should see my movie page 

Thus, your steps of the "new movie" will enter the field and send. And your β€œThen” will claim that the movie appears with your input.

 element = driver.find_element(:id, "movie_title") element.send_keys 'The Good, the Bad, the Ugly' # etc. driver.find_element(:id, "submit").click 

Now I'm just doing it, but this is what I came to. This certainly seems more verbose than something like Capybara:

 fill_in 'movie_title', :with => 'The Good, the Bad, the Ugly' 

Hope this helps.

+1
source

All Articles