简体   繁体   English

webelement 列表中的一些 wblements 值变为空白如何等待 webelement 的每个值出现在 selenium 中的 webelements 中

[英]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.

相关问题 如何更改硒列表中的值<Webelement> - how to change value in selenium List <Webelement> 使用列表设置类似的weblement <webelement> 硒中 - Setting up similar weblements using a list<webelement> in selenium 从 webelements 列表中获取具有最高值的 webelements 的方法 - method to get Webelement with highest value from list of webelements Java | 硒| 使用Stream从Weblement列表中返回单个Webelement - Java | Selenium | Using Stream to return single Webelement from a list of weblements 如何验证selenium中的数组列表WebElement更大和更低的值 - how to verify array list WebElement in selenium greater and lowest value 硒中的WebElements与WebElement的区别 - Difference WebElements Vs WebElement in selenium 如何在Java中检索Selenium WebElement的最小值? - How to retrieve a minimum value of a Selenium WebElement in Java? Selenium:如何在 for 循环中获取 webelement 的变化值 - Selenium: How to get the changing value of a webelement in a for loop 如何在硒中特定的Web元素内找到即时Web元素? - How to find immediate webelements inside particular webelement in selenium? selenium 等待刷新页面后,webelement 的状态从初始值“xxx”变为更改值“yyy”时如何处理? - How to tackle when the status of an webelement changes from initial value "xxx" to changed value "yyy" after the page refresh with selenium wait?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM