[英]some of the value of weblements in list of webelement are coming blank How to wait for each value of webelement to appear in webelements in selenium
ArrayList<String> corousalItems= new ArrayList<>();
List<WebElement> listText= driver.findElements(By.cssSelector("CorousalList"));
for (WebElement list : listText) {
String text=list.getText();
corousalItems.add(text);
}
System.out.println("List :"+corousalItems);
Some of the elements of above list are coming blank as value of those webelements are taking time to load.Need a way where driver can wait for the value to appear which can be added in the list.由于这些 webelement 的值需要时间来加载,因此上述列表中的某些元素将变为空白。需要一种方法让驱动程序可以等待可以添加到列表中的值出现。
Only 3 images are shown on corousal.在 corousal 上只显示了 3 个图像。 On clicking next bottom , corousal scrolls horizontally to 1 image.
单击下一个底部时,corousal 水平滚动到 1 个图像。 But on using CorousalList selector, able to locate the text that appears on corousal without clicking next button.
但是在使用 CorousalList 选择器时,无需单击下一步按钮即可定位出现在 corousal 上的文本。 The only issue is that some of the values are not loading so blank value is storing in list.
唯一的问题是某些值未加载,因此空白值存储在列表中。
You were close.你很接近。 To locate the desired elements you have to induce WebDriverWait for the
visibilityOfAllElementsLocatedBy()
and you can use the following solution:要找到所需的元素,您必须为
visibilityOfAllElementsLocatedBy()
引入WebDriverWait ,您可以使用以下解决方案:
ArrayList<String> corousalItems= new ArrayList<>();
List<WebElement> listText= new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("CorousalList")));
for (WebElement list : listText) {
String text=list.getText();
corousalItems.add(text);
}
System.out.println("List :"+corousalItems);
you can try something like this:enter code here你可以尝试这样的事情:在此处输入代码
ArrayList<String> corousalItems= new ArrayList<>();
List<WebElement> listText= driver.findElements(By.cssSelector("CorousalList"));
for (WebElement list : listText) {
wait.until((ExpectedCondition<Boolean>)driver->{
String text=list.getText();
return text.equals("")? false:true;
});
corousalItems.add(text);
}
System.out.println("List :"+corousalItems);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.