如果页面元素是一个下拉框,可以将此web元素封装为select对象
Select select=new Select(WebElement element);
Select select=new Select(WebElement element);
- Select 对象常用api
- select.getOptions();
- select.selectByIndex(index);
- select.selectByValue(value);
- select.selectByVisibleText(text);
eg:
//定位到下拉框
WebElement webElement = chromeDriver.findElement(By.name("gpc"));
//把WebElement封装成Select对象
Select select = new Select(webElement);
select.selectByIndex(1);
select.selectByVisible("最近一周");
//定位到下拉框
WebElement webElement = chromeDriver.findElement(By.name("gpc"));
//把WebElement封装成Select对象
Select select = new Select(webElement);
select.selectByIndex(1);
select.selectByVisible("最近一周");