对下拉框进行处理时,需要使用selenium封装的方法:
Select list = new Select(locator);
需要new一个select的类,通过select类的方法进行具体的元素定位。
具体的方法如下:
第一大类方法:选择对应的元素:1. Text(downlist.selectByVisibleText(“学生”))
2. Value(downlist.selectByValue("13");)
3. Index(downlist.selectByIndex(2);)
具体代码如下:
WebElement formjob = driver.findElement(By.id("profile"));//定位到整个表单
WebElement job = formjob.findElement(By.id("job"));//定位到select标签
System.out.println(job.isDisplayed());
Select downlist = new Select(job);//new一个select对象
//downlist.selectByIndex(2);//通过select对象进行元素定位,通过index定位
//downlist.selectByValue("13");//通过select对象进行元素定位,通过value定位
downlist.selectByVisibleText("页面重构设计"