Practice various Selenium WebElement Commands to automate the radio buttons, checkboxes, and drop-down menu on this form.
Use Select class for Select tag.
package exercises;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class Exercise4 {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.get("https://proleed.academy/exercises/selenium/automation-practice-form-with-radio-button-check-boxes-and-drop-down.php");
//Use select class
Select prefix= new Select(driver.findElement(By.id("prefix")));
prefix.selectByIndex(1);
driver.findElement(By.id("firstname")).sendKeys("Enter your Name");
driver.findElement(By.id("lastname")).sendKeys("Enter last name");
driver.findElement(By.id("pension")).click();
driver.findElement(By.name("fathername")).sendKeys("Enter Father Name");
driver.findElement(By.name("mothername")).sendKeys("Enter Mother Name");
driver.findElement(By.id("studentid")).click();
driver.findElement(By.id("identity_number")).sendKeys("Enter Identity number");
driver.findElement(By.id("male")).click();
Select month= new Select(driver.findElement(By.id("dob_month")));
month.selectByVisibleText("December");
Select date= new Select(driver.findElement(By.id("dob_date")));
date.selectByVisibleText("25");
Select year= new Select(driver.findElement(By.id("dob_year")));
year.selectByVisibleText("1985");
driver.findElement(By.id("single")).click();
Select countrycode= new Select(driver.findElement(By.id("country_code")));
countrycode.selectByVisibleText("Australia (+61)");
driver.findElement(By.id("mobile")).sendKeys("Enter mobile number here");
Select nationality= new Select(driver.findElement(By.id("nationality")));
nationality.selectByVisibleText("American");
driver.findElement(By.name("address")).sendKeys("enter address here");
driver.findElement(By.id("state")).sendKeys("enter state here");
Select country= new Select(driver.findElement(By.id("country")));
country.selectByVisibleText("Antarctica");
driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/form/div[15]/div[2]/input")).click();
}
}
Copyright © 2023 - Proleed Academy | All Rights Reserved.