Dropdowns
Validating dropdown options
Create a basic automation script that completes the test requirements listed below
Test Requirements
Verify the following elements
If needed click the plus sign for help
Verify that the form title is "Dropdowns"
Assert.assertEquals(driver.findElement(By.xpath(“//*[@id=\”wpforms-form-120\”]/div[1]/div”)).getText(),”Dropdowns”);
Verify that the Dropdown field is a dropdown with 3 options
Select select = new Select(driver.findElement(By.xpath(“//*[@id=\”wpforms-120-field_1\”]”)));
List<WebElement> dropdown = select.getOptions();
Assert.assertTrue(dropdown.size()==8);
Use Select to validate ALL options in the "Choose your preferred driver.findElement(By. option" dropdown
String options = “driver.maximize();,driver.Maximize();,driver.manage().maximize();,driver.manage().window().maximize();”;
String[] items = options.split(“\\s*,\\s*”);
Select select2 = new Select(driver.findElement(By.xpath(“//*[@id=\”wpforms-120-field_2\”]”)));
List<WebElement> list = select2.getOptions();
String[] outArray = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
outArray[i] = list.get(i).getText();}
for (int i = 0; i < items.length; i++) {
if (outArray[i].equals(items[i])) {
System.out.println(“passed on: ” + items[i]);
} else {
System.err.println(“failed on: ” + items[i]);
}
Close the WebDriver
driver.close();