Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

java - how to select element in multi select box in selenium webdriver

Currently working on Selenium WebDriver and using Java.. I want to know to select values in Multi-select box. The options are already selected.. If i want to select any two or more option. how can perform the action.

The HTML is follows:

<select id="swpacksId" multiple="" style="width: 125px; display: none;" name="swPacks[]">
<option selected="" value="ADVIP">ADVIP</option>
<option selected="" value="ADVLEG">ADVLEG</option>
<option selected="" value="ADVSEC">ADVSEC</option>
<option selected="" value="Boot">Boot</option>
<option selected="" value="H323">H323</option>
<option selected="" value="IBC">IBC</option>
<option selected="" value="MULTI">MULTI</option>
<option selected="" value="None">None</option>
</select>

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In a function pass a list of values use any delimiter lets say comma as a delimiter:

public static void selectMultipelValues(String multipleVals) {
   String multipleSel[] = multipleVals.split(",");

   for (String valueToBeSelected : multipleSel) {
      new Select(driver.findElement(By.id(propId))).selectByVisibleText(valueToBeSelected);
      driver.findElement(By.id(ddObj)).sendKeys(Keys.CONTROL);
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...