public class select {
public static void main(String[] args) throws InterruptedException {
//驱动配置信息
System.setProperty ( "webdriver.chrome.driver", "D:\\driver\\chromedriver.exe" );
WebDriver driver = new ChromeDriver ( );
driver.manage ( ).window ( ).maximize ( );
driver.get ( "http://www.w3school.com.cn/tiy/t.asp?f=html_select" );
//切换frame
driver.switchTo ( ).frame ( "i" );
//根据元素定位找到select标签
Select level = new Select ( driver.findElement ( By.tagName ( "select" ) ) );
//操作参数为 option 标签中属性值;
level.selectByValue ( "saab" );
//打印选择值并对结果进行断言打印
System.out.println ( "下拉框值选择为:" + level.getFirstSelectedOption ( ).getText ( ) +"\n"+ level.equals (level) );
driver.quit ( );
}
}