Pages

How to Select Last option in drop down using selenium ?


public class selectLastOption{

    public static void main(String[] args) {
        WebDriver driver;
        System.setProperty("webdriver.chrome.driver", "F:\\chromedriver\\chromedriver_latest\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        WebElement e=d.findElement(By.id("selecttype"));
        Select s=new Select(e);
        List<WebElement> eles=s.getOptions();
        int lastIndex=eles.size()-1;
        s.selectByVisibleText(eles.get(lastIndex).getText());
}


Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.