Looking for duplicate links in a page

I’m not sure of a way already built into Katalon…but I would recommend playing with script view you can do so much with it.

However if you are ok with it here is the code to copy and paste. This would work better as a keyword but here is the raw code:

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

// get the text of the body element
WebDriver driver = DriverFactory.getWebDriver();
WebElement body = driver.findElement(By.tagName("body"));
String bodyText = body.getText();

// count occurrences of the string
int count = 0;

// search for the String within the text
while (bodyText.contains("Writer's Name Here")){

    // when match is found, increment the count
    count++;

    // continue searching from where you left off
    bodyText = bodyText.substring(bodyText.indexOf("Writer's Name Here") + "Writer's Name Here".length());
}

countIs = count.toString()
WebUI.comment(countIs)

I found and modified this from https://stackoverflow.com/questions/18442895/how-many-times-a-text-appears-in-webpage-selenium-webdriver/18449828

1 Like