Clicking on a javascript button

I am trying to get acquainted with Katalon, addmittedly I am extremely and pleasantly surprised by how capable Katalon is.

I am creating test cases that are dealing with problems that many GUI testers see as a problem for codeless GUI automation tools: Javascript heavy websites.

Right now my test case is failing because it’s trying to click a button that doesn’t contain a link, but rather this:

<div class="smallb">
        <div class="smallbLeft" onclick="this.onmouseout();axiom_lastClickedEl=this;cb_showPromotionInp();" style="background-position: left top;" onmouseover="axiom_buttonLeftOnMouseOver(this)" onmouseout="try {axiom_buttonLeftOnMouseOut(this)} catch(e){};"><div class="smallbIcon" style="background-image:url(/bookeo/simg-3/sb/promotion.png)"></div></div>
        <div class="smallbRight" role="button" onclick="this.onmouseout();axiom_lastClickedEl=this;cb_showPromotionInp();" onmouseover="axiom_buttonRightOnMouseOver(this)" onmouseout="try {axiom_buttonRightOnMouseOut(this)} catch(e){};" style="background-position: right top;">Enter code</div>
</div>

I used the record button to create my test case but when I click the script view I see this:
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 internal.GlobalVariable as GlobalVariable

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘https://www.cascadebreweryco.com.au/agegate?destination=’)

WebUI.setText(findTestObject(‘Page_ Cascade Brewery/input_Jump to navigation_day’), ‘10’)

WebUI.setText(findTestObject(‘Page_ Cascade Brewery/input_Jump to navigation_month’), ‘12’)

WebUI.setText(findTestObject(‘Page_ Cascade Brewery/input_Jump to navigation_year’), ‘1991’)

WebUI.click(findTestObject(‘Page_ Cascade Brewery/input_Remember me next time I’))

WebUI.click(findTestObject(‘Object Repository/Page_Cascade Brewery/a_Jump to navigation_meanmenu- (1)’))

WebUI.click(findTestObject(‘Object Repository/Page_Cascade Brewery/a_X’))

WebUI.click(findTestObject(‘Object Repository/Page_Cascade Brewery/a_Book a tour’))

WebUI.clickOffset(findTestObject(‘Page_Book A Tour Cascade Brewery/div_Enter code’), 1, 1)

WebUI.setText(findTestObject(‘Page_Book A Tour Cascade Brewery/input_Promotionvoucher code__p’), ‘valid’)

WebUI.click(findTestObject(‘Page_Book A Tour Cascade Brewery/li_VALID Invalid coupon code’))

With the following error:

Elapsed time: 46,268s

Test Cases/Javascript test FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/Page_Book A Tour Cascade Brewery/div_Enter code’ using offset x=1 and y=1 (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_Book A Tour Cascade Brewery/iframe_Book A Tour_easyXDM_axi’ located by ‘By.xpath: //iframe[@id=‘easyXDM_axiomct_project_default8321_provider’]’ not found)
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:65)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:27)
at com.kms.katalon.core.webui.keyword.builtin.ClickOffsetKeyword.clickOffset(ClickOffsetKeyword.groovy:59)
at com.kms.katalon.core.webui.keyword.builtin.ClickOffsetKeyword.execute(ClickOffsetKeyword.groovy:39)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.clickOffset(WebUiBuiltInKeywords.groovy:645)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$clickOffset$3.call(Unknown Source)
at Javascript test.run(Javascript test:34)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1548672761493.run(TempTestCase1548672761493.groovy:22)

Can anyone help me? Is it necessary to use javascript here and where / how do i enter it?

Katalon (and the underlying Selenium) will try to simulate a “physical” click on the given element. This usually works fine, but there are instances where it’s insufficient. If you want to try to use JavaScript to click it instead, see this thread:

1 Like

Just noticed this part of your error. You actually need to switch to the iframe first, then your click (normal click here, but this is true for JavaScript click as well) should work. You will need a Test Object for the iframe, then use the following to switch to it:

WebUI.switchToFrame(iframeObject, 30);

1 Like

You’re absolutely right. I am going to try this. Finding the correct iframe could pose to be a challenge in a web application that consists of multiple different iframes and a dynamic dom structure. If it fails I will come back here.

1 Like