Is there a way to count the elements in selenium webdriver. Ie I have:
<div id="test">
<div class="Computer"></div>
<div class="Computer"></div>
<div class="Computer"></div>
</div>
I need to get an amount of the div.Computer
. I've tried to use:
List<WebElement> v_ct = Login.driver.findElements(By.cssSelector(".Computer"));
System.out.println("The amount s "+v_ct.size());
But amount is 0 instead 3.
Use explicit wait before you grab the list. The elements are not properly loaded.
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".Computer")));
List<WebElement> v_ct = Login.driver.findElements(By.cssSelector(".Computer"));
System.out.println("The amount s "+v_ct.size());
var num = document.querySelectorAll('*').length //returns the length of your node list,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.