Manual Actions
- Check display status
- Check Enabled status
- Select an Item
- Return item count
Selenium WebDriver Steps
package HandlingElementsInSelenium;
import java.util.List;
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;
public class HandlingDropdown {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://rahulshettyacademy.com/AutomationPractice/");
WebElement dropdownBox = driver.findElement(By.id("dropdown-class-example"));
//Check Display status
boolean status = dropdownBox.isDisplayed();
System.out.println("DropDown Box is displayed :- "+status);
//Check enabled status
status = dropdownBox.isEnabled();
System.out.println("DropDown Box is enabled :- "+status);
//Expand and select value of dropdown by index
Select dropdown = new Select(dropdownBox);
dropdown.selectByIndex(02);
Thread.sleep(2500);
System.out.println(dropdown.getFirstSelectedOption().getText());
//Check item count
List <WebElement> x = dropdown.getOptions();
System.out.println("Size of dropdown box is :- "+x.size());
driver.close();
}
}
Next