I have list of web element, when I apply listName.size() function on list, it shows count as 1.
Where as in actual the count is not 1.
以下是我尝试过的事情 -
- Tried applying implicit and explicit wait in order to load the long list of web elements properly.
- Tried wait.until(ExpectedConditions.visibilityOfElementLocated(listName));
java代码:
List<WebElement> listName= driver.findElements(By.xpath("xpath"));
int count = listName.size();
我希望计数与使用 xpath 找到的列表元素的数量完全相同。 注意:xpath 有效且正确。可以使用该 xpath 手动定位元素。
最佳答案
如果您的用例是打印与特定 Locator Strategy 匹配的 List 的 size()
您需要使用以下任一解决方案,而不是使用 visibilityOfElementLocated()
:
visibilityOfAllElements(WebElement... elements)
:System.out.println(new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfAllElements(driver.findElements(By.xpath("xpath")))).size());
visibilityOfAllElementsLocatedBy(By locator)
:System.out.println(new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("xpath"))).size());
关于java - 通过 Java 使用 Selenium 显示计数为 1 的 WebElements 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55969775/