Issue clicking web element in salesforce lightning

Hi guys,

I ran into the similar problem as described in: I am not able to click on a web element in salesforce lightning application

I tried the solution provided there and change the links/objects accordingly to my situation:

// Wait upto 10 seconds for a_Accounts to be visible...
WebUI.waitForElementVisible(findTestObject('Local_OPP/Page_Home  Salesforce/span_Opportunities'), 10)

// Wait an additional, full 10 seconds...
/* ****** */ WebUI.delay(10) /* ****** */

WebUI.executeJavaScript('''document.querySelector('a[href="/lightning/o/Opportunity/home"] > span').click()''', null)

// this was original solution from recording
//'Local_OPP/Page_Home  Salesforce/span_Opportunities'))

But when I play the test case, error occurs:
10-08-2019 04:03:22 PM Test Cases/INTPack/New Opportunity object

Elapsed time: 25.214s

Test Cases/INTPack/New Opportunity object FAILED.
com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$ Source)
	at New Opportunity Opportunity object:34)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
	at com.kms.katalon.core.main.TestCaseExecutor.execute(
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source)
Caused by: org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'click' of null
  (Session info: chrome=76.0.3809.132)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LTCZAEBS9RTMPQ2', ip: '', 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 76.0.3809.132, chrome: {chromedriverVersion: 76.0.3809.68 (420c9498db8ce..., userDataDir: C:\Users\LUKAS~1.RER\AppDat...}, goog:chromeOptions: {debuggerAddress: localhost:54800}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 6f6b6a4055d58518462a0c384bbbc367
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(
	at org.openqa.selenium.remote.RemoteWebDriver.execute(
	at com.kms.katalon.selenium.driver.CChromeDriver.execute(
	at org.openqa.selenium.remote.RemoteWebDriver.executeScript(
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.doCall(ExecuteJavascriptKeyword.groovy:48)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	... 17 more

This part of the error is what matters:

That means, 'a[href="/lightning/o/Opportunity/home"] > span' is not a valid object (it’s null).

You can confirm this in your browser console. Bring up the page, and paste this in the browser console:

document.querySelector('a[href="/lightning/o/Opportunity/home"] > span')

Run that and post a screenshot of the results.

I’m also concerned about this:

Can you please provide “your situation”. I.e. show me your code and a screenshot of the relevant HTML.


Ok, thought it’s just a link, not an object. I’ll look into that during the day, still newbie, dunno where to find console :slight_smile:

Just short update before I get back with results: original solution worked, when I used absolute XPath from ChroPath (both relative XPath and CSS fails).

Console et al can be found here:

Thanks, did not knew there was a console in this Tab. So the output of the JS code in console is only: “null”. But that’s weird, in screen you can see exactly the same link.

Lower you can find whole code:



WebUI.setText(findTestObject('Object Repository/Local_OPP/Page_Login  Salesforce/input_Username_username'), '')

WebUI.setEncryptedText(findTestObject('Object Repository/Local_OPP/Page_Login  Salesforce/input_Password_pw'), '3Z9vEXbPUsBb8kkQDDKxXw==')'Object Repository/Local_OPP/Page_Login  Salesforce/input_Password_Login'))

// Wait upto 10 seconds for a_Accounts to be visible...
WebUI.waitForElementVisible(findTestObject('Local_OPP/Page_Home  Salesforce/span_Opportunities'), 10)

// Wait an additional, full 10 seconds...
/* ****** */ WebUI.delay(10) /* ****** */

WebUI.executeJavaScript('''document.querySelector('a[href="/lightning/o/Opportunity/home"] > span').click()''', null)

//'Local_OPP/Page_Home  Salesforce/span_Opportunities'))'Object Repository/Local_OPP/Page_Recently Viewed  Opportunities  Salesforce/div_New'))

Sounds like it’s in an iframe. And this seems to confirm it:

In the browser console again:


We’re hoping for zero, but I’m guessing it’s not.

console answer is 1

So now you (we) need to prove that <a href=...> is residing inside the <iframe...> element.

Return to your DevTools, find the <a href=...> element and “walk” up the tree until you find the <iframe> element. When you find it, take another screenshot - try to show both the iframe and the a-element in the same shot.

My intention is to build you some JS/CSS to reach the a-element. I need to see the entire “scope” to do that.

No, no iframe tag found, until the top of this DevTool screen (until the beginning doctype html tag). I screened max of the code - I would paste whole, but did not found a way how to copy it from the DevTool. If it’s just the html page I guess I can copy it from there.

Weird thing is, that when I used yesterday Katalon Recorder extension for Chrome, I did not have problem with this part. And second weird thing is, that this object is in the same menu, as the problem I linked in my first post.

Try this in the console. Send me a screenshot of the output:


Console result is: Uncaught TypeError: Cannot read property ‘click’ of null at <anonymous>:1:66

Well, at least it’s consistent.

I’m starting to wonder if there’s some shadow dom trickery going on here. I honestly think I’ve reached the end of my remote debugging skills.

I have to ask, what prompted you to move from the absolute paths? Did you say that those worked?

I was just trying what will work, that’s how I found the absolute Xpath. But from what I’ve read, the absolute Xpath will probably crash with new SalesForce update.

So I am currently in my “PoC” stage - if it makes sense in our company to make the Katalon implementation bigger. If I fail on first scenario recording and will know that I will need to debug the tests with each update because of absolute Xpaths, the business case will suffer a blow…

Other question - can I somehow import the recording from Chrome extension to Katalon studio? I need to edit it because of the dynamic IDs on pop-up screens (I’ve read solution in another topic). But the problem is, I could not edit these things in the extension. And export seemed in kind of weird HTML filetype…

Well, you shouldn’t allow my failure to help you judge the merits of Katalon Studio. Sitting in front of your PC, I’d very likely have this working in 5 minutes.

Let’s try a callout to some other people - hopefully a fresh set of eyes will find something I missed.

@Ibus @Brandon_Hein @ThanhTo @devalex88

@Russ_Thomas Don’t worry and thanks for help. I see Katalon as powerful tool, but the recording part has gaps, whatever the solution of this problem is.

Please try window.frames[0].document.querySelector("a[href='/lightning/o/Opportunity/home']") in the console and let me know the result.

1 Like

Response of console is: null

If possible please copy the whole HTML and send me. You can send a private message if it is sensitive.


In addition to what you’re doing for @devalex88, please try this…

Run your stuff against Firefox and try the same things in the console. If you see any significant difference, we’d like to see what those are. You can choose any of the console things… doesn’t matter which ones.