Issue clicking web element in salesforce lightning

So when I inspect this element, from FF:

From Chrome:

Now try the various console bits, like:

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

document.querySelector(“a[href=’/lightning/o/Opportunity/home’]”)
FF null, CH: null

window.frames[0].document.querySelector(“a[href=’/lightning/o/Opportunity/home’]”)
FF null, CH: null

document.querySelector(“a[href=’/lightning/o/Opportunity/home’]”).click()
FF: TypeError: document.querySelector(…) is null
CH: Uncaught TypeError: Cannot read property ‘click’ of null
at :1:66

document.querySelector(‘a[href="/lightning/o/Opportunity/home"] > span’)
FF: SyntaxError: illegal character
CH: Uncaught SyntaxError: Invalid or unexpected token

It’s looking like you have much the same results.

However, this one…
image

is caused by you copying the forum text after it was rendered in the forum. The forum Discourse software has the annoying “feature” that it likes to use “pretty quotes” which are not seen as proper quotes in JavaScript. (@devalex88 if there’s a way to turn this feature off please do - it’s a pain in the posterior).

ok, so I removed both simple quotes and the result is:
document.querySelector(a[href="/lightning/o/Opportunity/home"] > span)
FF: ReferenceError: a is not defined
CH: Uncaught ReferenceError: a is not defined
at :1:24

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

Everything inside ( ... ) needs to be in one type of quotes. Inside those quotes, you need to use a different type of quotes. So, you can either do

this: " ' ' "
or
this: ' " " '

We are using the last combination.

Ok, I get it :slight_smile:

So the result is:
FF: null
CH: null

Crazy.

Is this site public? (You can PM me if you prefer).

Otherwise, we’ll wait for Alex.

@devalex88, @Russ_Thomas

Because this is standard object in SalesForce, you can inspect by yourself. It would be for sure faster, than me, handling the code :slight_smile:
I created SalesForce developer sandbox. I’ve checked, and the code looks pretty much the same as in our test ORG.

Thanks very much for your help!

URL: https://login.salesforce.com
Login: katalon.developer@yopmail.com
Pass: katalon123

Because you will login to setup, you need to switch to Sales cloud, to see the Menu with Opportunities (but the mechanism is probably same for any item in the menu in any of the clouds).

Go to 9 dots on the left side of menu and click, then on the right side you will see Sales module. After the cloud reloads, you will see the targeted menu. (see screenshot below how to switch)

Sorry. This is outside my comfort zone.

:smiley: yopmail is public email, anyone can access. The developer ORG I created is public to anyone too.

@lukas.rericha I was able to click Sales module successfully. To click on the sales module use the below xpath.

//a[text()=‘Sales’]

<a class="appTileTitle" aria-labelledby="visibleDescription_07p3k000000PG6sAAG" id="appTile" data-aura-rendered-by="267:2640;a" href="/lightning/app/06m3k000000zkHDAAY" draggable="false">Sales</a>

When I checked the page, there is no frames available.

1 Like

Hi @discover.selenium ,

thanks for your help, but the issue is one step further. When you load the Sales module, there is menu, where is the “Opportunities” item - this menu/item is the issue for relative Xpath.

I am getting the below error now.

image

Issue from session probably or someone else logged. I tried now and it was ok. Please try fresh session - log out, then https://login.salesforce.com

Hope you want to click on ‘Opportunities’ as mentioned in the below screenshot

image

Below is the html of the same

<a href="/lightning/o/Opportunity/home" title="Opportunities" tabindex="0" draggable="false" aria-describedby="operationId-15" class="slds-context-bar__label-action dndItem"> <span class="slds-truncate">Opportunities</span></a>

Method:1 Working fine
WebUI.click(findTestObject('SaleForce/Menu_Oppurtunity'))

Method:2
I have a dirty trick to handle this: It did work for me.

href = WebUI.getAttribute(findTestObject('SaleForce/Menu_Oppurtunity'), 'href')

System.err.println href

WebUI.navigateToUrl(href)

SaleForce/Menu_Oppurtunity test object xpath is //a[@title=‘Opportunities’]

image

PS: There is no frame or shadow dom available.

for Method 1 - I need to retest at work on Monday, because my Windefender say some Katalon functions are blocked on firewall. But current results are:

10-16-2019 09:46:07 AM Test Cases/OPP_new_2

Elapsed time: 1m - 9.386s

Test Cases/OPP_new_2 FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to click on object 'Object Repository/SF/Menu_Opportunity'
	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.ClickKeyword.click(ClickKeyword.groovy:86)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:67)
....

I’ve rewritten the first object (Opportunities_span) from original scenario, it didn’t work. So I did then the fresh recording with this object, again did not work. So I created fresh new object as your screenshot is:

the code underneath the scenario is:

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 org.openqa.selenium.Keys as Keys

WebUI.openBrowser('')

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

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

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

WebUI.click(findTestObject('Object Repository/Page_Login  Salesforce/input_Password_Login'))

// Wait upto 10 seconds for Opportunities to be visible...
WebUI.waitForElementVisible(findTestObject('SF/Menu_Opportunity'), 10)

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

WebUI.click(findTestObject('Object Repository/SF/Menu_Opportunity'))

WebUI.click(findTestObject('Object Repository/Page_Recently Viewed  Opportunities  Salesforce/div_New'))

WebUI.click(findTestObject('Object Repository/Page_New Opportunity  Salesforce/span_Next'))

WebUI.setText(findTestObject('Object Repository/Page_New Opportunity Opportunity Local  Salesforce/input__683473a'), 'new_OPP_01')

WebUI.click(findTestObject('Object Repository/Page_New Opportunity Opportunity Local  Salesforce/button_Save'))

WebUI.closeBrowser()

I will try the second method.

for Method 2, dunno where exactly to put the code, so I exchanged it for this line:

WebUI.click(findTestObject('Object Repository/SF/Menu_Opportunity'))

The result is:

10-16-2019 10:01:11 AM Test Cases/OPP_new_2

Elapsed time: 1m - 8.169s

Test Cases/OPP_new_2 FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to get attribute 'href' of object 'Object Repository/SF/Menu_Opportunity'
	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.GetAttributeKeyword.getAttribute(GetAttributeKeyword.groovy:93)
	at com.kms.katalon.core.webui.keyword.builtin.GetAttributeKeyword.execute(GetAttributeKeyword.groovy:68)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getAttribute(WebUiBuiltInKeywords.groovy:921)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$getAttribute$5.call(Unknown Source)
	at OPP_new_2.run(OPP_new_2:35)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)

Could the issue with method 1 be that there is the browser pop-up with notification, which is somehow colliding with the scenario / focus?

@discover.selenium

So I tried method 1 at work and it failed:

10-23-2019 10:33:36 AM Test Cases/OPP_new_2

Elapsed time: 1m - 4.806s

Test Cases/OPP_new_2 FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to get attribute 'href' of object 'Object Repository/SF/Menu_Opportunity'
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)