Xpath query not working

Hi all. I’m using Katalon Studion 5.10.1 - build 1 on a Server 2012 R2 box.

I’m building a test case and am having problems being able to identify an element to click on it. It’s nested within about 6 DIV commands.

When recording the test, it identified the element as
But when I try and play or debug this, it fails with a Web Element not found. I’ve tried the Xpath within Chrome and Firefox and both CAN detect what’s going on - they find a single element within the document fine.
I’ve played around with other Xpath parameters to try and find it (begins-with) etc - but I’m just going round in circles.

The element is:
<button id="sc-button-" class="close" ng-disabled="scDisabled" ng-click="myClickFn()" type="" focused=""> <ng-transclude><span aria-hidden="true" class="ng-scope">×</span></ng-transclude> </button>


1 Like

The XPath from the recorder looks fine to me. My guess is that you need a wait condition to make sure the element is present in the DOM before trying to click:

WebUI.waitForElementPresent(buttonObject, 30);

If that doesn’t help, we’ll probably need more info. In particular, it would be nice to see the entire error log, as well as your test code leading up to and including the failure.

Hope this helps!

Edit: One other possibility came to mind. We should also make sure that the element is not sitting with in an iframe of some sort.


It looks like some sort of a close button. So, probably you need to wait for it to appear and switch to the iframe possibly.

Already tried looking for an iframe in the source - which there isn’t. Will try a wait.
Cheers for the suggestions!

No joy. Here’s the error log:
01-29-2019 08:25:40 AM Test Cases/S1

Elapsed time: 1m - 22.239s

Test Cases/S1 FAILED.
com.kms.katalon.core.exception.StepFailedException: Unable to click on object 'Object Repository/Page_Sophos Central/button_' (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/Page_Sophos Central/button_' located by 'By.xpath: //button[@id='sc-button-']' 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.ClickKeyword.click(ClickKeyword.groovy:86)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:67)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$3.call(Unknown Source)
	at SophosCentralWithAdminUser.run(SophosCentralWithAdminUser:66)
	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 TempTestCase1548750335975.run(TempTestCase1548750335975.groovy:22)

And here’s the script to that point:
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
import com.kms.katalon.core.testdata.InternalData as InternalData

data = findTestData('BTLSDataFile')



WebUI.setText(findTestObject('Object Repository/Page_Sophos Central/input_Email Address_username (1)'), '###')

WebUI.setEncryptedText(findTestObject('Object Repository/Page_Sophos Central/input_Password_password (1)'), '###')

WebUI.click(findTestObject('Object Repository/Page_Sophos Central/button_Sign In'))

WebUI.click(findTestObject('Object Repository/Page_Sophos Central/form_SECURITY CODE'))

WebUI.setText(findTestObject('Object Repository/Page_Sophos Central/input_SECURITY CODE_code (1)'), '###')

WebUI.click(findTestObject('Object Repository/Page_Sophos Central/button_Submit'))

for (def index : (0..data.getRowNumbers() - 1)) {
    WebUI.click(findTestObject('Object Repository/Page_Sophos Central/span_Sub-Estates'))

    WebUI.click(findTestObject('Object Repository/Page_Sophos Central/button_New Sub-Estate (1)'))

    WebUI.setText(findTestObject('Object Repository/Page_Sophos Central/input__name (1)'), data.internallyGetValue('Schoolname', 

    WebUI.click(findTestObject('Object Repository/Page_Sophos Central/label_I Expressly acknowledge'))

    WebUI.click(findTestObject('Object Repository/Page_Sophos Central/span_Sophos Privacy Policy_ter (1)'))

    WebUI.click(findTestObject('Object Repository/Page_Sophos Central/button_Create Sub-Estate (1)'))

    WebUI.click(findTestObject('Object Repository/Page_Sophos Central/button_Close (1)'))

    WebUI.setText(findTestObject('Object Repository/Page_Sophos Central/input_Enterprise Super Admin_e'), data.internallyGetValue(
            'Schoolname', index))


    WebUI.click(findTestObject('Object Repository/Page_Sophos Central/input_Phish Threat_sub-estate-'))

    WebUI.click(findTestObject('Object Repository/Page_Sophos Central/button_Launch Sophos Central A'))


    not_run: WebUI.scrollToElement(findTestObject('Page_Sophos Central/span_Endpoint Protection'), 3)

    not_run: WebUI.click(findTestObject('Page_Sophos Central/span_Endpoint Protection'))

    WebUI.click(findTestObject('Page_Sophos Central/button_'))

I’ve tried with a variety of different Xpath formats - and within the Webspy utility I’ve had the page up for half an hour or more trying to get it to identify that element which it steadfastly refuses to do - even after creating a new test case and using that newly created Xpath for the button.

Did you try waiting for the element?

Can you locate the element by xpath manually in DevTools?

wait didn’t work, and nor could I find the element with the spy utility, but I could in chrome, firefox and IE when running on their own via the element inspector.

Got round this by a workaround - calling a separate URL directly.

Hi Ash

I’m sure Mate and Brandon have given you great advice (which, working with you remotely is not easy, as i’m sure you’re aware) and I’m glad you found a way to get around the issue. However…

If your test was meant to mimic what a user would do (most tests fall into that category) then the workaround sounds as though you’re side-stepping the issue and doing something a user would not (maybe even could not) do. Plus, we’re (you’re) not learning anything if you do that.

It would really benefit you AND the community to figure out what the true issue is – don’t you think?

What exactly did you do in the inspector?

What is the xpath provided by the inspector/right-click?

Did you try using a CSS path? What was the result?