自动执行语义UI下拉菜单

时间:2018-10-04 08:46:42

标签: java selenium selenium-webdriver semantic-ui

如何使用Java自动实现硒中的语义UI dropdown

它不适用于此代码:

Select drpdwn1 = new Select(driver.findElement(By.cssSelector("#ddIssue")));
int sel1Size = drpdwn1.getOptions().size();
for (int i = 0; i < sel1Size; i++) {
  drpdwn1 = new Select(driver.findElement(By.cssSelector("#ddIssue")));
  drpdwn1.selectByIndex(i);
  driver.findElement(By.xpath("//*[@id=\"ticketMessage\"]")).sendKeys(" test");
}

DOM HTML代码是-

<div class="ui fluid dropdown search selection active visible">
<select id="ddIssue" name="IssueTypeId">
 <option value="">SelectIssueType</option>
 <option value="12">test isssue type</option>
 <option value="13">Test</option>
 <option value="14">tester</option>
</select>
 <i class="dropdown icon"></i>
 <input class="search" autocomplete="off" tabindex="0">
  <div class="default text">SelectIssueType</div>
  <div class="menu transition visible" tabindex="-1" style="display: block !important;">
    <div class="item" data-value="12">test isssue type</div>
    <div class="item" data-value="13">Test</div>
    <div class="item" data-value="14">tester</div>
  </div>
</div>

3 个答案:

答案 0 :(得分:0)

尝试以下代码从下拉菜单中选择“测试”值:

 Select drpCountry = new Select(driver.findElement(By.name("IssueTypeId")));

    List <WebElement> count= drpCountry.getOptions();
    int size= count.size();

    for(int i =0; i<size ; i++){
            String value = count.get(i).getText();
            System.out.println(value);
            drpCountry.selectByIndex(i);
        }

答案 1 :(得分:0)

Select oSelect = new Select(driver.findElement(By.name("IssueTypeId")));
        List<WebElement> oSize = oSelect.getOptions();
        int iListSize = oSize.size();
        // Setting up the loop to print all the options
        for(int i =0; i < iListSize ; i++){
            // Storing the value of the option  
            String sValue = oSelect.getOptions().get(i).getText();
            // Printing the stored value
            System.out.println(sValue);
            oSelect.selectByIndex(i);
            Thread.sleep(2000);
            }

答案 2 :(得分:0)

stat_function(...)

如果这不起作用,则发布您遇到的错误或异常。