# Problem to solve
Supposing the target web page has a list of element.
I want to verify the displayed contents against other list of strings list like this:
def expectedContents = [
"Tokyo CURA Healthcare Center",
"Hongkong CURA Healthcare Center",
"Seoul CURA Healthcare Center" ]
However, in the built-in keywords of Katalon Studio, there is none which returns the contents of HTML elements as List.
# My Solution
I have developed a class com.kazurayam.ksbackyard.FindElementsByXPath . This class provides 2 custom keywords.
- List getElementContentsAsList(String xpath4elements)
- List getElementAttributesAsList(String xpath4elements, String attributeName)
A sample Test Case looks like this:
def expectedContents = [ "Tokyo CURA Healthcare Center",
"Hongkong CURA Healthcare Center",
"Seoul CURA Healthcare Center" ]List<String> cs = CustomKeywords.'com.kazurayam.ksbackyard.FindElementsByXPath.getElementContentsAsList'('//select[@name="facility"]/option')
for (int i = 0; i < cs.size(); i++) {
WebUI.verifyEqual(cs[i], expectedContents[i])
}
def expectedValues = [
"Tokyo",
"Hongkong",
"Seoul" ]
List<String> vs = CustomKeywords.'com.kazurayam.ksbackyard.FindElementsByXPath.getAttributeValuesAsList'('//select[@name="facility"]/option', 'value')
for (int i = 0; i < vs.size(); i++) {
WebUI.verifyEqual(vs[i], expectedValues[i])
}
# My implementation
See the following GitHub repository: