(十三)定位下拉菜单select
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Checkbox</title>
</head>
<body>
<h3>select</h3>
<select id="selType">
<option value="0">请选择</option>
<option value="1">原创</option>
<option value="2">转载</option>
<option value="4">翻译</option>
</select>
</body>
</html>
可以通过索引、值、文本定位选项:
import org.openqa.selenium.support.ui.Select;
driver.get("file:///C:/Users/administrator/Desktop/select.html");
new Select(driver.findElement(By.id("selType"))).selectByIndex(3);
new Select(driver.findElement(By.id("selType"))).selectByValue("4");
new Select(driver.findElement(By.id("selType"))).selectByVisibleText("翻译");;