user3538483
user3538483

Reputation: 193

How to count the products on a page using selenium?

is there any way to count the all available products in a e-commerce web site?

below is the html.

Cargo Pants

Upvotes: 0

Views: 2549

Answers (2)

Androdos
Androdos

Reputation: 693

Basically

List<WebElement> list = driver.findElements(By.id(repeating_element_ID));
int itemsCount = list.size();

where findElements is right function for resolve this issue, because it returns list of items located by By-locator (id, xpath, name, ...). Then you can count elements by function size() on given list.

Upvotes: 1

Aliscuse
Aliscuse

Reputation: 11

I am not sure about what you are looking for, but in selenium there is a method to find elements in the browser:

List<WebElement> wel = null;
String newElement = (element_to_locate);

wel = this.getDriver().findElements(By.id(newElement));

Upvotes: 1

Related Questions