I have used click, enhanced click and click with javascript – all pass but nothing happens with the object. The object is supposed to move from the upper grid section on a page to a lower grid section.
Any ideas why all three methods would say passed but nothing happens on the page?
The click using JS method I am calling:
//click object using Javascript
def clickUsingJS(TestObject to, int timeout) {
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = WebUiCommonHelper.findWebElement(to, timeout)
JavascriptExecutor executor = ((driver) as JavascriptExecutor)
executor.executeScript('arguments[0].click()', element)
}
The katalon code:
def acceptOne = WebUI.getText(findTestObject('Object Repository/Page_Investment and Capacity Planning/ICP17_Accept Analyze Initiatives/div_First Top Item Description'))
println('>>>>>>>>>>>' + acceptOne)
WebUI.click(findTestObject('Object Repository/Page_Investment and Capacity Planning/ICP17_Accept Analyze Initiatives/div_First Top Item Description'))
//topItemOne = WebUI.modifyObjectProperty(findTestObject('Object Repository/Page_Investment and Capacity Planning/ICP17_Accept Analyze Initiatives/div_DynamicTopItem'),
// 'text', 'equals', acceptOne, true)
WebUI.click(findTestObject('Object Repository/Page_Investment and Capacity Planning/ICP17_Accept Analyze Initiatives/span_Upper Pane Ellipses'))
WebUI.delay(1)
def rawXpath = '''//span[@title='DYN_VALUE']/../../../../../../../../../../../../../../../../../../../../..//span[@class='icon12']'''
def editXpath = rawXpath.replace('DYN_VALUE', acceptOne)
def acceptAnalyze = WebUI.modifyObjectProperty(findTestObject('Object Repository/Page_Investment and Capacity Planning/ICP17_Accept Analyze Initiatives/span_Analyze'), 'xpath', 'equals', editXpath, false)
WebUI.click(acceptAnalyze)
Have you done a test of the HTML to ensure the xpath, or whatever you are using, is correct for the element you want?
Certainly I can give you a reason the JavaScript calls might fail. Does the element (or its ancestor nodes) have a click
event handler? If so, you need to ensure it is triggered, also.
If you use firefox to inspect the dom for the page, you can check if the element has event handlers. You’ll see a small button event next to the element. Click it and check what event handlers are present.
Here’s an example from this page (the one you’re reading now)
As @grylion54 has alluded to, when you click and the test passes but nothing happens in the UI, it’s usually an indication that you are not clicking on the correct element. For example, you can click on any <div>
, even one that has no functional purpose in your app (maybe it’s for formatting or something), and the test code doesn’t care as long as that element is visible and clickable.
Can you share the HTML for the item you are intending to click? Please share what you think is the correct element, as well as some of the surrounding HTML so we can see if maybe there’s something else you should be targeting.
Thanks! There are two click
event handlers.
function(evt) {
onLeaveFastTrackItem();
spec.onClick.handler(evt);
}
&&&
function(e) {
return "undefined" != typeof S && S.event.triggered !== e.type ? S.event.dispatch.apply(t, arguments) : void 0
}
and here’s the HTML:
Try this code to click the element in question.
String js = 'document.querySelector("div.bannerMenu.right[id$=ipm-accepted-grid] a:nth-of-type(2)").click();'
WebUI.executeJavaScript(js, null);
I’m not proposing this as the ultimate fix, we just need to see if something is working. Small steps…
Yeah my guess here is that the locator in your test object is pointing at a span element, as evidenced by the name of your test object (‘Page_Investment and Capacity Planning/ICP17_Accept Analyze Initiatives/span_Analyze’).
Try targeting the parent <a>
element instead. I’m not sure what your locator looks like currently, but here’s an xpath to find the icon, then traverse back up to the parent link:
//ul[@class='fasttrack']//span[contains(@class, 'Analyze')]/ancestor::a
1 Like
In this program, usually clicking a span works.
I changed the code to find the <a>
element based on a relative xpath and same issue, still passes but nothing changes on the page.
def acceptOne = WebUI.getText(findTestObject('Object Repository/Page_Investment and Capacity Planning/ICP17_Accept Analyze Initiatives/div_First Top Item Description'))
def xpathLink = '''//span[@class='grid-drag-handle-label-container'][normalize-space()='DYN_VALUE']/../../../../../../../../../../../../../../../../../../../../..//a[@class='fasttrack-menuitem-container']'''
def editXpath = xpathLink.replace('DYN_VALUE', acceptOne)
TestObject dynamicScenarioMenuObject = new TestObject('dynamicObject').addProperty('xpath', ConditionType.EQUALS, editXpath, true)
WebUI.click(dynamicScenarioMenuObject)
Am I supposed to modify this or anything? This doesn’t work, says:
Caused by: org.openqa.selenium.JavascriptException: javascript error:
Cannot read properties of null (reading 'click')
Usually being the operative word. Generally speaking, you will have more consistent results if you target actionable elements rather than spans/divs/etc. Actionable elements are your <a>
's, <input>
's, <button>
's, etc.
def acceptOne = WebUI.getText(findTestObject('Object Repository/Page_Investment and Capacity Planning/ICP17_Accept Analyze Initiatives/div_First Top Item Description'))
def xpathLink = '''//span[@class='grid-drag-handle-label-container'][normalize-space()='DYN_VALUE']/../../../../../../../../../../../../../../../../../../../../..//a[@class='fasttrack-menuitem-container']'''
def editXpath = xpathLink.replace('DYN_VALUE', acceptOne)
TestObject dynamicScenarioMenuObject = new TestObject('dynamicObject').addProperty('xpath', ConditionType.EQUALS, editXpath, true)
WebUI.click(dynamicScenarioMenuObject)
I’m not sure what you’re trying to do here, I assume all of this is so that you can parameterize your locator to reuse it for clicking other icons in the fasttrack. There is a better way to do this, but lets not worry about that for now. Try this simple code, just as a test, and see if clicking the <a>
element works as expected:
// get the current web driver that katalon is using:
WebDriver driver = DriverFactory.getWebDriver();
// find the element using the xpath I shared above:
WebElement element = driver.findElement(By.xpath("//ul[@class='fasttrack']//span[contains(@class, 'Analyze')]/ancestor::a"));
// click using plain old selenium:
link.click();
// if it doesn't work, click using JavaScript:
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
Instead of fussing with Katalon’s WebUI API, we’re just using plain old Selenium. This makes things easier to test, as it removes the middleman. If this works, then you know that the xpath I used should work if you then place it in a Test Object and use Katalon as usual.
I’ll be honest with you – I’m not a software developer and when I read the doc pages about parameterizing I could not figure it out. I know that’s probably what I should be doing in many places, but simply cannot figure out what it means or how it works. Also could not find a great explanatory tutorial.
As for actionable elements – That’s good advice. There are many repetitions of actionable items on the page without unique IDs. Like little carrots for dropdown menus everywhere, so I need to find them with xpaths based on nearby objects. Usually the spans are easier to find but as I now see that’s not th best method… -sigh-
I used the auto-import feature to get the packages.
For your script, I’m getting an error for link.click()
that says:
Reason:
groovy.lang.MissingPropertyException: No such property: link for class: Script1641260697161
That’s because I made a typo
my bad. Here’s the correct code:
// get the current web driver that katalon is using:
WebDriver driver = DriverFactory.getWebDriver();
// find the element using the xpath I shared above:
WebElement element = driver.findElement(By.xpath("//ul[@class='fasttrack']//span[contains(@class, 'Analyze')]/ancestor::a"));
// click using plain old selenium:
element.click();
// if it doesn't work, click using JavaScript:
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
Excellent. The script you wrote worked. Then I created a new Test Object using the xpath and re-ran using that object with WebUI.click and it worked as well.
Thank you!
1 Like
Excellent, I’m glad we could resolve the issue. I will mark the appropriate reply as the answer to this thread.