Selenium webdriver 获取下拉列表中的所有选项,并使用SeleniumWebDriver和java将其与单个选项进行比较
有谁能告诉我如何获得下拉列表中的所有选项,并使用selenium web驱动程序将其与单个选项进行比较 我试用过这个代码Selenium webdriver 获取下拉列表中的所有选项,并使用SeleniumWebDriver和java将其与单个选项进行比较,selenium-webdriver,Selenium Webdriver,有谁能告诉我如何获得下拉列表中的所有选项,并使用selenium web驱动程序将其与单个选项进行比较 我试用过这个代码 Select dropdown = new Select(_driver.findElement(EventListOptionList)); List<WebElement> Options = dropdown.getOptions(); for (WebElement el : Options) { if(
Select dropdown = new Select(_driver.findElement(EventListOptionList));
List<WebElement> Options = dropdown.getOptions();
for (WebElement el : Options) {
if(el.getText.equals("event1")){
System.out.printLn("Option is present")
}
}
Select下拉菜单=新选择(_driver.findElement(EventListOptionList));
List Options=dropdown.getOptions();
对于(WebElement el:选项){
if(el.getText.equals(“event1”)){
System.out.printLn(“存在选项”)
}
}
但它显示了这一行的错误
List<WebElement> Options = dropdown.getOptions();
List Options=dropdown.getOptions();
错误是“删除类型参数”您必须已导入此列表类:“java.awt.List”。因此出现了错误。
请将其删除并导入“java.util.List”。这肯定会解决您的问题。您能提供HTML代码段吗?这是特定行的编译时错误还是运行时错误?太棒了……)如果这对您有帮助,请将其标记为答案。谢谢。:)