我正在使用selenium(java)编写多选的代码,我需要执行以下任务:
我有这个代码,它返回我未定义的第二个任务的结果。
public class MultipleSlectList {
public static WebDriver driver ;
@BeforeTest
public void startbrowser () throws Exception {
System.out.println("launching browser");
System.setProperty("webdriver.gecko.driver", "H:\\Selenium3\\geckodriver-v0.19.1-win32\\geckodriver.exe");
driver = new FirefoxDriver();
driver.get("http://www.seleniumeasy.com/test/basic-select-dropdown-demo.html");
}
@Test
public void selectlist () throws Exception {
WebElement ele1 = driver.findElement(By.id("multi-select"));
Select se= new Select(ele1);
se.selectByValue("New Jersey");
Thread.sleep(2000);
se.selectByValue("Texas");
Thread.sleep(2000);
se.selectByValue("Florida");
Thread.sleep(2000);
//Thread.sleep(10000);
WebElement btn1= driver.findElement(By.id("printMe"));
btn1.click(); // it is supposed to return New Jersy
WebElement firstOption = se.getFirstSelectedOption();
System.out.println("The First selected option is::" +firstOption.getText());
List <WebElement> oSize = se.getAllSelectedOptions();
int iListSize = oSize.size();
// Setting up the loop to print all the options
for (int i = 0; i < iListSize; i++)
{
// Storing the value of the option
String sValue = oSize.get(i).getText();
// Printing the stored value
System.out.println(sValue);
}
}
}
请帮我进一步。
我也试过jquery但没有运气。结果与&#34; undefined&#34;相同。在这两种情况下。
谢谢!
答案 0 :(得分:0)
选择所有下拉选项的步骤:
下面的文章有代码示例来实现上述场景。
http://www.dev2qa.com/select-dropdown-list-selenium-webdriver/