Hello!
I am currently trying to figure out how script the process of finding duplicate links on a webpage. I started with using suggestions from Looking for duplicate links in a page - #4 by B_L, but I’ve run into some difficulties. Primarily, because the page links change daily, I can’t just do a search for the same text or URL every time.
The code I have so far is:
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.logging.KeywordLogger as KeywordLogger
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.webui.common.WebUiCommonHelper as WebUiCommonHelper
WebUI.openBrowser(‘’)
WebUI.navigateToUrl(‘mycompanyswebpage.com’)
WebUI.click(findTestObject(‘links object folder/linknamegoeshere’))
WebUI.delay(60)
WebUI.click(findTestObject(‘links object folder/pageobjectgoeshere’), FailureHandling.CONTINUE_ON_FAILURE)
List links = WebUiCommonHelper.findWebElements(findTestObject(‘links’), 30)
int linkCount = 0
int comparisonCount = 0
KeywordLogger log = new KeywordLogger()
for (WebElement link : links) {
String text = link.getText()
for (WebElement k : links) {
if (k != link) {
if (k.getText().equals(text)) {
comparisonCount++
linkCount++
log.logInfo(comparisonCount.toString())
}
}
}
}
assert linkCount <= 1
WebUI.closeBrowser()
Some of the issues I’m running into:
-the code compares the links to all the other links on the page, but won’t show where the duplicates occur.
-the list of links wasn’t created as a table but rather as a stack of divs, I tried looking at some documentation on counting values in a table but it wasn’t effective.
Is there anything else I can do? The page is pulling links in from another source and I’m trying to ensure that it isn’t accidentally pulling data twice (which would cause a link to display twice in this case).
Thank you!