I am trying to loop through the list of a webelement and get the text. So I can verify the text is same as expected
in my script
By menuListObj = By.cssSelector(“.navigation-wrapper .navigation-menu .navigation-menu-item a”)
CustomKeywords.‘ciautils.ciaUtilities.verifyNavMenu’(driver, menuListObj, careerNavbarList)
def verifyNavMenu(WebDriver driver, By object, List expectedMenuName){
List menuNameInApp = driver.findElements(object)
tried these both options but the output is shown as below
Option1
for (String s : menuNameInApp){
println (s)
}
Option2
for (int i = 0; i <menuNameInApp.size(); i++){
String actualMenuName = menuNameInApp.get(i).getText()
println(i+1 +". menu name "+actualMenuName )
If (actualMenuName == expectedMenuName(i)){
println(“Sucess”)
}
else{
println(“Failed”)
}
}
}
Output
menu name [[CChromeDriver: chrome on WINDOWS (23024dcbcb923168d4e308da435981ad)] → css selector: .navigation-wrapper .navigation-menu .navigation-menu-item a]
menu name [[CChromeDriver: chrome on WINDOWS (23024dcbcb923168d4e308da435981ad)] → css selector: .navigation-wrapper .navigation-menu .navigation-menu-item a]
menu name [[CChromeDriver: chrome on WINDOWS (23024dcbcb923168d4e308da435981ad)] → css selector: .navigation-wrapper .navigation-menu .navigation-menu-item a]
Not sure why its printing the selector and not the text
I am wondering why the parentheses } is missing, which closes the definition of function verifyNavMenu. If } is there or not — it is semantically very important. Is } really missing? or carelessly omitted in that quotation only?
I tried the above change and still not working. Not sure why a simple line of selenium script not working in katalon studio.
All I am trying to do is get the list of elements and gettext from each element in the array. This works when I try on selenium. But in this tool its printing the locator instead of text. Am I missing anything here
Finally got the issue fixed, this is all because of not waiting for the page to load. after trying a wait statement then it worked. Thanks for everyones support though
I am getting following error
11: to.addProperty(“CSS”, EQUALS, “div .utility-navigation”)
2020-01-29 11:35:30.221 ERROR c.k.katalon.core.main.TestCaseExecutor - Test Cases/Career_Landingpage FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: ConditionType for class: Script1580161905483
Hi @ThanhTo, it seems like adding a property of css type is not working, I am getting following error
11: obj.addProperty(“CSS”, EQUALS, “div .utility-navigation”)
12: waitForElementClickable(obj, 10)
Unable to find the element located by ‘By.xpath: //[@CSS = ‘div .utility-navigation’]'. Please recheck the objects properties to make sure the desired element is located.
2020-01-29 12:18:53.996 WARN k.c.w.k.b.WaitForElementClickableKeyword - Web element with id: ‘’ located by 'By.xpath: //[@CSS = ‘div .utility-navigation’]’ not found
But if I try xpath then its working. Just want to let you know for now its fine for me. If I need to use it in future with css will there be any thing I can do
Ah my mistake, that piece of code adds a property to Test Object, so css property will not be read and interpreted by Katalon, but xpath property will. If you want to properly set a CSS selector then there are other APIs on Test Object too.