2016-02-29 202 views
1

我們如何使用硒從Excel工作表中取消選中列表框中的值從Excel工作表中取消選中列表框中的值的webdriver我們如何使用硒的webdriver

,上面寫着從Excel工作表「的UserRole」值代碼這裏

<div class="col-md-8 blockBox"> 
<select class="required userroles" message="Select User Role" multiple="yes" size="3" name="UserRoles"> 
<option value="45"> BIS Super Admin </option> 
<option value="7"> BIS Senior Admin </option> 
<option selected="" value="3"> Learner </option> 
<option value="30"> Manager </option> 
<option value="48"> Reporting </option> 
<option value="51"> Senior Reporting </option> 
<option value="4"> Reporting Manager </option> 
<option value="31"> Senior Reporting Manager </option> 
<option value="40"> Proctor Manager </option> 
<option value="50"> Content Manager </option> 
<option value="47"> Admin Manager </option> 
<option value="49"> Location Admin </option> 
<option value="33"> Course Admin </option> 
<option value="42"> Client Admin </option> 
<option value="46"> Client Senior Admin </option> 
<option value="38"> Public Retail Learner </option> 
</select> 
</div> 

代碼這裏

driver.findElement(By.name("UserRoles")).sendKeys(s.getCell(15,rowCnt).getContents()); 

我想從Excel工作表中取消選擇或不選擇「UserRoles」值。

回答

1

您可以使用Select這個

Select select = new Select(driver.findElement(By.name("UserRoles"))); 
select.deselectAll(); 
// or 
select.deselectByValue("3"); 
// or 
select.deselectByVisibleText("Learner");