Is there a way to verify doubled element?

I have two same html elements on page.

                                        <h2 class="category-main__big-title">Страница не найдена, воспользуйтесь поиском<br>

                        или ссылками ниже</h2>

                                </div>

                                <h2 class="category-main__big-title">Страница не найдена, воспользуйтесь поиском<br>

                    или ссылками ниже</h2>  

How do i check if there is one or two elements on page?

Hello there,

you can use native WebDriver method to get a list of elements with the same identifier and then get a number of them.

import org.openqa.selenium.Byimport org.openqa.selenium.WebDriverimport com.kms.katalon.core.webui.driver.DriverFactory

String xpath = "yourXpathHere"WebDriver driver = DriverFactory.getWebDriver()List<WebElement> elems = driver.findElements(By.xpath(xpath))int numberOfElements = elems.size()

1 Like

Thanks a lot. It works. Also i have to add this:

import org.openqa.selenium.WebElement as WebElement