How to get array size based on an element found using Xpath?

This is what I usually write in Selenium webdriver when I want to find size of an array/table.


int rowcount = Driver.findElements(By.xpath(“html/body/div[1]/div/div/form/table[2]/tbody/tr”)).size();

int colcount = driver.findElements(By.xpath(“html/body/div[1]/div/div/form/table[2]/tbody/tr[2]/td”)).size();
System.out.println(“The column count is:”+colcount);

Thank you, Vinh!

I got the error “Test Cases/Test 1 FAILED because (of) Variable ‘By’ is not defined for test case.” because it cannot find org.openqa.selenium.WebDriver. Where should I place selenium-server-standalone-3.4.0.jar and tell Katalon Studio its location? Thanks in advance.

Thanks Vinh…

It works like a charm:)

Vinh? I dont see the answer Is there a solution for this ?

I don’t see the answer too… :frowning:

You need to add this import: import org.openqa.selenium.By

Hi there,

In Katalon Studio, it’s the same:

import org.openqa.selenium.WebDriver

import com.kms.katalon.core.webui.driver.DriverFactory

WebDriver driver = DriverFactory.getWebDriver()

rowcount = Driver.findElements(By.xpath("html/body/div[1]/div/div/form/table[2]/tbody/tr")).size()