从下拉列表中选择值不使用angularJS应用程序
下拉类中的选项的HTML。从下拉列表中选择值不使用angularJS应用程序,angularjs,selenium,selenium-webdriver,Angularjs,Selenium,Selenium Webdriver,下拉类中的选项的HTML。 注意:我不想使用javascriptexecutors。您可以在此处更改该选项的xpath //span[text()=“一般问题”] 您还可以使用不同的定位器,如css选择器。 请通过遍历选项列表查找访问该选项的代码: <li class="enabled _msddli_"> <span class="ddlabel" style="background-color: transparent;">General Question</s
注意:我不想使用javascriptexecutors。您可以在此处更改该选项的xpath //span[text()=“一般问题”] 您还可以使用不同的定位器,如css选择器。 请通过遍历选项列表查找访问该选项的代码:
<li class="enabled _msddli_">
<span class="ddlabel" style="background-color: transparent;">General Question</span>
String str=“一般问题”;
选择列表=新选择(driver.findElement(By.id(“提及您正在使用的下拉定位器”));
List listSize=List.getOptions();
int-iListSize=listSize.size();
//System.out.println(iListSize);
//设置循环以选择所有选项
对于(int j=0;j
虽然遍历下拉列表需要一些时间,但您可以尝试一下!!希望这有帮助!!HTML代码中是否存在
元素?请尝试在dd中的选项选择之前进行预期的等待,可能会有所帮助\@Andersson感谢您的回复。No@rajNishKuMar:已经有一个等待,直到被c在该步骤1之前调用-OP没有要求对所有选项2进行迭代-Select
仅对
标记3起作用-问题在于单击,而不是定位元素。
<li class="enabled _msddli_">
<span class="ddlabel" style="background-color: transparent;">General Question</span>
String str="General Question";
Select list= new Select(driver.findElement(By.id("mention the drop down locator you are using")));
List<WebElement> listSize = list.getOptions();
int iListSize = listSize.size();
// System.out.println(iListSize);
// Setting up the loop to select all the options
for(int j =0; j < iListSize ; j++){
// Storing the value of the option
String sValue = list.getOptions().get(j).getText();
// Selecting all the elements one by one
if (sValue.equalsIgnoreCase(str){
list.selectByVisibleText(sValue);
Thread.sleep(50);
}
}