Activity: Filling in a Form and Submitting It

Review and analyze the structure and behavior of the https://trainingbypackt.github.io/Beginning-Selenium/lesson_3/exercise_3_1.html file.

  1. Create a new Java file for the automation script. Make sure that you include the required libraries:
package com.beginningselenium.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
  1. Locate the textbox of id firstName, and input some text. In this case, input "John":
WebElement firstName = driver.findElement(By.id("firstName"));
firstName.sendKeys("John");
  1. Locate the textbox of id lastName, and input some text. In this case, input "Doe":
WebElement lastName = driver.findElement(By.id("lastName"));
lastName.sendKeys("Doe");
  1. Locate the dropdown list of id dayOfBirth; select the option "20" by sending its value:
Select dayOfBirth = new Select(driver.findElement(By.id("dayOfBirth")));
dayOfBirth.selectByVisibleText("20");
  1. Locate the dropdown list of id monthOfBirth; select the option "March" by sending its value:
Select monthOfBirth = new Select(driver.findElement(By.id("monthOfBirth")));
monthOfBirth.selectByVisibleText("March");
  1. Locate the dropdown list of id yearOfBirth; select the option "1990" by sending its value:
WebElement yearOfBirth = driver.findElement(By.id("yearOfBirth"));
yearOfBirth.sendKeys("1990");
  1. Locate the dropdown list of id hobbies; select these two options: Reading and Sports:
Select hobbies = new Select(driver.findElement(By.id("hobbies")));
hobbies.selectByVisibleText("Reading");
hobbies.selectByVisibleText("Sports");
  1. Locate the radio button "Masters"; select a radio button by clicking on it after it has been selected:
WebElement masters = driver.findElement(By.cssSelector("input[value='masters']"));
masters.click();
  1. Locate the checkbox emailUpdates and enable the "I want to receive email updates" field:
WebElement emailUpdates = driver.findElement(By.id("emailUpdates"));
emailUpdates.click();
  1. Locate the text area of id aboutYourself, and input some text:
WebElement aboutYourself = driver.findElement(By.id("aboutYourself"));
aboutYourself.sendKeys("I think Selenium is getting easier and easier!");
  1. Include an instruction to click on the Submit button:
WebElement submit = driver.findElement(By.id("submit"));
submit.click();
  1. Compile and run the script.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.244.83