首页 > 技术文章 > (十三)定位下拉菜单select

TestAndDevelp 2019-06-21 15:21 原文

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

 

推荐阅读