如何使用selenium selenium.select("","")选择下拉列表中的值?

Vin*_*nod 2 java selenium selenium-rc

我正在使用Selenium进行自动化.我正在使用DefaultSelenium课程,在我们的应用程序中我有一个下拉菜单.我想从这个下拉列表中获得一个值.

最初,我使用selenium IDE编写脚本,它给了我以下代码:

selenium.select("id=skuOptionSIZE1c4b403", "label=8");
Run Code Online (Sandbox Code Playgroud)

但是当我开始用代码(Java)编写时,Eclipse会抛出一个错误,而我仍然能够看到id页面上的下拉列表:

Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Element id=skuOptionSIZE1cd7bfd not found
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我如何从下拉中获取价值?

Tar*_*ken 5

如果您使用的是Selenium 2 aka Webdriver,我会这样做:

Select select = new Select(driver.findElemetn(/*Way to your drop down*/));
select.selectByValue("your value") 
//or
select.selectByVisibleText("your Test");

//alternativly you can do something like this
List<WebElement> options = select.getOptions();
//find your desired option
select.selectByVisibleText(option.getText());
Run Code Online (Sandbox Code Playgroud)

希望有所帮助.