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();
}
}
}
我在select.selectByIndex(5)行获得ElementNotVisibleException,有人可以在这方面帮助我吗?
答案 0 :(得分:1)
在冒险选择选项之前,您可能需要等到下拉列表实际可见:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@class='para_small']")))