Java 如何验证下拉列表是否已经预先填充了selenium中的值

Java 如何验证下拉列表是否已经预先填充了selenium中的值,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我需要验证一个下拉列表是否预先填充了文本“All”,该文本在selenium中使用JAVA显示在下拉列表中。有人能帮忙吗? 下面是HTML代码 <div _ngcontent-c3="" class="input-group"> <span _ngcontent-c3="" class="input-group-addon"><i _ngcontent-c3="" class="fa fa-flash"></i></span>

我需要验证一个下拉列表是否预先填充了文本“All”,该文本在selenium中使用JAVA显示在下拉列表中。有人能帮忙吗? 下面是HTML代码

<div _ngcontent-c3="" class="input-group">
  <span _ngcontent-c3="" class="input-group-addon"><i _ngcontent-c3="" class="fa fa-flash"></i></span>
  <select _ngcontent-c3="" class="form-control m-b ng-untouched ng-pristine ng-valid" id="report-status-id-select" name="reportStatusId">
    <!---->
    <option _ngcontent-c3="" value="0: 0">All</option>
    <option _ngcontent-c3="" value="1: 4">In Action</option>
    <option _ngcontent-c3="" value="2: 5">Completed</option>
    <option _ngcontent-c3="" value="3: 6">Closed</option>
    <option _ngcontent-c3="" value="4: 10">PJP</option>
  </select>                         
</div>

全部的
行动中
完整的
关闭
PJP
选择下拉菜单=新选择(driver.findElement(By.id(“id”)));
//获取所有选项
List dd=下拉列表。getOptions();
//了解长度
System.out.println(dd.size());
//循环以逐个打印
对于(int j=0;j
试试这个

Select select = new Select(driver.findElement(By.xpath("//path_to_drop_down")));

WebElement option = select.getFirstSelectedOption().getText( );
看看这个

请参阅:SO的期望是,用户提问时不仅要进行研究以回答自己的问题,还要分享研究、代码尝试和结果。这表明你花了时间来帮助自己,它使我们避免重复显而易见的答案,最重要的是,它帮助你得到一个更具体和相关的答案!另见:
Select select = new Select(driver.findElement(By.xpath("//path_to_drop_down")));

WebElement option = select.getFirstSelectedOption().getText( );