要先选中这个弹出层的form元素,再找下拉框
public void downSelectBox(){driver.get("https://www.imooc.com/user/setprofile");driver.findElement(By.className("pull-right")).click();try {Thread.sleep(2000);} catch (InterruptedException e) {// TODO Auto-generated catch block e.printStackTrace();}//先获取弹出层的form表单WebElement formElement = driver.findElement(By.id("profile"));WebElement job = formElement.findElement(By.id("job"));Select downList = new Select(job);downList.selectByIndex(2);//downList.selectByValue("1");//downList.selectByVisibleText("学生");downList.selectByIndex(3);//这个只能取消多选下拉框//downList.deselectByIndex(3);List<WebElement> list = downList.getAllSelectedOptions();for(WebElement option : list){System.out.println(option.getText());}System.out.println(downList.getFirstSelectedOption().getText());}