<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("翻譯");;