selenium webdriver 操作select
@Test public void test() { WebDriver driver=ExplorerBase.IESetting(); driver.get("http://uniquepig.iteye.com/signup"); driver.manage().window().maximize(); //<option value="在读学生">在读学生</option> Select select = new Select(driver.findElement(By.id("user_gender"))); select.selectByVisibleText("男"); select=new Select(driver.findElement(By.id("user_occ")));//user_occ select.selectByVisibleText("软件测试");//获取的是标签之间的值 select=new Select(driver.findElement(By.id("user_workyear")));//user_workyear select.selectByValue("两年以上");//获取的是value select=new Select(driver.findElement(By.id("user_industry")));//user_industry select.selectByIndex(1);//根据索引获取 //System.out.println(select.getFirstSelectedOption().getText()); /* * 不选择对应的选择项: select.deselectAll(); select.deselectByValue(“MA_ID_001”); select.deselectByVisibleText(“mediaAgencyA”); 或者获取选择项的值: select.getAllSelectedOptions(); select.getFirstSelectedOption(); * */ }