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
// WebUI.click(findTestObject('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.
Reason:
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$5.call(Unknown Source)
	at New Opportunity object.run(New Opportunity object: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:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1570543399782.run(TempTestCase1570543399782.groovy:21)
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: '10.46.3.13', os.name: '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(W3CHttpResponseCodec.java:187)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
	at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:20)
	at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:489)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.doCall(ExecuteJavascriptKeyword.groovy:48)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.call(ExecuteJavascriptKeyword.groovy)
	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.

Thanks

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.openBrowser('')

WebUI.navigateToUrl('https://test.salesforce.com/')

WebUI.setText(findTestObject('Object Repository/Local_OPP/Page_Login  Salesforce/input_Username_username'), 'branchuser1@yopmail.com.focore.intv2')

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

WebUI.click(findTestObject('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)

// WebUI.click(findTestObject('Local_OPP/Page_Home  Salesforce/span_Opportunities'))

WebUI.click(findTestObject('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:

frames.length

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:

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

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.

@lukas.rericha

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.