Thursday, June 12, 2014

How to Select Last value from the WebList without using getOptions() ?

WebElement dropDown = driver.findElement(By.xpath("//select")); //xpath of dropdown may be different, here just giving example

Select sel = new Select(dropDown);
List<WebElement> options = driver.findElements(By.xpath("//select//options"));
int numOfOptions = options.size();
sel.selectByIndex(numOfOptions-1); //this will select last value from the dropdown but this logic will work when html code has been developed with select tag

No comments:

Post a Comment