Review and analyze the structure and behavior of the https://trainingbypackt.github.io/Beginning-Selenium/lesson_3/exercise_3_1.html file.
- 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;
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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();
- Locate the checkbox emailUpdates and enable the "I want to receive email updates" field:
WebElement emailUpdates = driver.findElement(By.id("emailUpdates"));
emailUpdates.click();
- 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!");
- Include an instruction to click on the Submit button:
WebElement submit = driver.findElement(By.id("submit"));
submit.click();
- Compile and run the script.