How to iterate in Pagination drop down having values 10,25,50,100 in the drop-down using for loop

huangapple go评论79阅读模式
英文:

How to iterate in Pagination drop down having values 10,25,50,100 in the drop-down using for loop

问题

Here is the translated code portion:

另一种迭代并选择所有下拉框值的方法

Select dropdown = new Select(WebUIDriver.webDr.findElement(By.xpath("输入xpath")));
int noOfDropDownValues = dropdown.getOptions().size() - 1;

for (int i = 0; i < noOfDropDownValues; i++) {
    new Select(WebUIDriver.webDr.findElement(By.xpath("输入Xpath"))).selectByValue(String.valueOf(i));
}
英文:

enter image description here

Another method to iterate and select all the Dropdown values

Select dropdown= new Select(WebUIDriver.webDr.findElement(By.xpath(&quot;enter xpath&quot;)));
int noOfDropDownValues=  dropdown.getOptions().size()-1;

for(int i=0;i&lt;noOfDropDownValues;i++){
    new Select(WebUIDriver.webDr.findElement(By.xpath(&quot;Enter Xpath&#39;]&quot;))).selectByValue(String.valueOf(i));
}

答案1

得分: 1

使用Select类可能无法正常工作,因为它仅适用于带有Select标签的元素,但您可以尝试按索引选择它们,这将逐个选择下拉菜单中的所有选项。

Select dropdown = new Select(WebUIDriver.webDr.findElement(By.xpath("输入XPath")));
int noOfDropDownValues = dropdown.getOptions().size();

for (int i = 0; i < noOfDropDownValues; i++) {
    dropdown.selectByIndex(i);
}
英文:

Without seeing the html code its hard to tell if using Select Class will work, as it only works with elements with Select Tag but you can try doing selecting them by index, this will select all options in dropdown one by one

        Select dropdown = new Select(WebUIDriver.webDr.findElement(By.xpath(&quot;enter xpath&quot;)));
    	int noOfDropDownValues = dropdown.getOptions().size() ;

	    for (int i = 0; i &lt; noOfDropDownValues; i++) {
		dropdown.selectByIndex(i);
	    }

huangapple
  • 本文由 发表于 2023年5月10日 19:07:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76217667.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定