[英]Java Selenium webdriver filling list webelement manually
first of all: I want to fill a List manually with element.add();
首先:我想用
element.add();
手动填充列表element.add();
Because the elements of the page I am working with is just showing a specific range of elements, I can't just load all elements in a List<WebElement>
. 因为我正在使用的页面元素仅显示特定范围的元素,所以我不能仅将所有元素加载到
List<WebElement>
。
That's why I want to do functions to check if an element exists
in my List, if it doesn't exists there I will add it. 这就是为什么我要执行函数以
check if an element exists
列表中是否check if an element exists
,如果不存在check if an element exists
,则将其添加。
I want to know if there is a way to iterate specific elements like element.next();
我想知道是否有一种方法可以迭代特定元素,例如
element.next();
Here is the xpath I am getting my elements: 这是我正在获取元素的xpath:
###.findElement(By.xpath(".//a[starts-with(@href, '/p/')]"));
You ca use following snippet to fulfill your requirement 您可以使用以下代码段满足您的要求
public boolean isDropdownOptionExists(String optionToBeVerified, By optionWhereToBeVerified) {
boolean isOptionFound = false;
Select optionsInDropDown = new Select(driver.findElement(optionWhereToBeVerified));
List<WebElement> availableOptions = optionsInDropDown.getOptions();
for(WebElement option: availableOptions) {
if(option.getText().equals(optionToBeVerified)) {
isOptionFound = true;
break;
}
}
return isOptionFound;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.