user3296744
user3296744

Reputation: 169

Not able to select an option from the dropdown leading to ElementNotVisibleException

import java.util.List;
import java.util.concurrent.TimeUnit;
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.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class DellDropdown {

    public static void main(String[] args) {
        WebDriver driver=new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.get("http://www.dell.com/");
        WebElement dropdown=driver.findElement(By.xpath("//select[@class='para_small']"));
        Select select=new Select(dropdown);
        select.selectByIndex(5);
        List<WebElement> options=select.getOptions();
        for(int i=0;i<options.size();i++)
        {
            options.get(i).getText();
        }
    }
}

I am getting the ElementNotVisibleException on at line select.selectByIndex(5), can someone help me in this regard?

Upvotes: 0

Views: 228

Answers (1)

aquaraga
aquaraga

Reputation: 4168

You may have to wait until the drop down is actually visible, before you venture to select the options:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@class='para_small']")))

Upvotes: 1

Related Questions