I can't click elements in Salesforce

I want to automate operations in Salesforce.
I want to click the elements of the list displayed on the left side of the setting screen, but I can not find it.
Both xPath and image recognition resulted in an error. Thank you for your support.
The image will be the content of the specified xPath and error.

OS version: Windows 10 / Use browser: GoogleChrome / RPAExpress version: 2.3.2.1287


Hi @hana perhaps, this element is located inside an iframe.
In this case, you need to provide the XPath of the iframe, too.

Thank you for your early reply, @ashapkina
However, iframe is not used on this page.
I can not find iframe’s xPath.
Not only elements of “user” but also text areas etc. can not be acquired.
What should I do now.

Can you share the details of the error and the HTML code of the whole page?

Thank you for your reply. I understand the cause.
This page is open in a new tab from the previous page.
I confirmed that you can click an element by opening the URL of this page directly.
But why do I get an error when opened in a new tab while in the same browser?
I added a Window action to switch to this page when opened in a new tab, but it didn’t work.
Is there a way to continue processing with the new tab? Thank you.

Also, the details of the error that occurred are as follows.

Error executing MouseClickAction
  com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=MouseClickAction.ftl,id=12,name=Optional[MouseClickAction],parent=11,arguments=ActionArguments[exactMatch=[true],imageName=[C:\\SalesForce\\rpae_project\\LEX\u691C\u8A3C\\1560918821569-anchor-1560918821623.apng],fullImageName=[1560918821569.png],xsi:type=[recorder:MouseClickAction, recorder:MouseClickAction],pollingInterval=[300],active=[true],searchInFrames=[false],type=[IMAGE],button=[1],anchorOffsetX=[7],delay=[3000],timeoutMs=[10000],webElementLocatorType=[XPATH],webElementLocator=[//*[@class='filter-box input']],awaitTimeout=[5000]]]
      at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:54)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
      at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.openqa.selenium.WebDriverException: Build info: version: '9.3.1.0', revision: 'ef4b445edf', time: '2019-05-29T11:53:16.301Z'
System info: host: 'C36541800286790', ip: '10.75.60.133', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: com.freedomoss.crowdcontrol.webharvest.selenium.wrapper.RemoteDriverWrapper
Capabilities [{imageSimilarityThreshold=0.8, extra.executor.id={Name=RPA Recorder}, CLOSE_ALL_WINDOWS=false, browserName=universal, javascriptEnabled=true, extra.capabilities.context={"browserType":"universal","startInPrivate":false,"blockImages":false,"maximizeOnStartup":false,"customCapabilities":{"platform":"WINDOWS","javascriptEnabled":true,"SEARCH_ALL_WINDOWS":true,"CLOSE_ALL_WINDOWS":false,"imageSimilarityThreshold":"0.8"},"executorId":{"Name":"RPA Recorder"}}, platformName=WINDOWS, SEARCH_ALL_WINDOWS=true, platform=WINDOWS}]
Session ID: 00328312-46d5-4e99-9e10-f72316ca080c
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
      at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
      at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:41)
      at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
      at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:741)
      at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:677)
      at com.workfusion.rpa.helpers.ImageElement.findImageCoordinates(ImageElement.java:156)
      at com.workfusion.rpa.helpers.ImageElement.getCoordinates(ImageElement.java:69)
      at com.workfusion.rpa.helpers.ImageElement.click(ImageElement.java:63)
      at com.workfusion.rpa.helpers.UiElement.click(UiElement.java:997)
      at org.openqa.selenium.WebElement$click.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
      at Script13.run(Script13.groovy:9)
      at com.workfusion.studio.rpa.recorder.playback.shell.GroovyShellWrapper.executeScript(GroovyShellWrapper.java:48)
      at com.workfusion.studio.rpa.recorder.playback.player.PlaybackContext.executeScript(PlaybackContext.java:108)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.executeBehavior(TemplateAction.java:33)
      at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:46)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
      at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.NullPointerException
1 Like

The focus of the driver stays on the same tab, so if you work with several tabs in the browser, you need to switch between them in a custom script to be able to use XPaths.

You can find examples of custom scripts here: https://kb.workfusion.com/display/RPAe/Code+Samples#CodeSamples-Switchingbetweenwindows/tabs

Thank you for the sample.
I was able to click when I put CustomAction.
But there are things that I do not know.
It works correctly when executed in recording, but it causes an error when executed in bot task.
Do you know anything about this cause? Thank you.

Can you share the bot task code?

Attach bot task code.Thank you.
Click processing after CustomScriptAction results in an error.

    timeouts().pageLoadTimeout(20000, java.util.concurrent.TimeUnit.MILLISECONDS)

                openChrome(UrlOperations.ensureProtocol("https://playful-hawk-6h29zp-dev- ed.lightning.force.com/lightning/page/home"))

                window().maximize()

                $(byXpath("//*[@id=\"username\"]")).setValue(String.valueOf(user))

                $(byXpath("//*[@id=\"password\"]")).setValue(String.valueOf(pass))

                $(byXpath("//*[@id=\"Login\"]")).click()

                inDesktop {
                    switchToExistingWindow(new WindowDescriptor("Chrome_WidgetWin_1", "\u30DB\u30FC\u30E0 | Salesforce - Google Chrome", false, false).toString(), 10000)
                }

                sleep(2000)

                $(byXpath("//*[@class=\'slds-icon\']")).click()

                inDesktop {
                    sendKeys(StringTransformations.getKeyPressText(57424, 0, 40, 0))
                }

                inDesktop {
                    sendKeys(StringTransformations.getKeyPressText(28, 13, 10, 0))
                }

                @CustomScriptAction(
                )

                def customScript() {
                    driver().switchToLastWindow()
                }

                // Do not remove! Custom action customScript will be invoked here.
                customScripActionCall_customScript: {}

                sleep(3000)

                $(byXpath("//*[@id=\"split-left\"]/div/div/div/ul/li[5]/div/a")).click()

                $(byXpath("//*[@id=\"split-left\"]/div/div/div/ul/li[5]/ul/li[2]/div/a")).click()

                sleep(3000)

Is this the only custom script in the recording or are there several?

This is the only place that uses CustomScript.
Thank you.

Did you just export the recording to bot task without changing anything?

Sorry for the late reply.
I just exported the code and I made no changes.

  1. Execute recording with embedded custom script (it will not be an error)
  2. Export to source code
  3. Run the source code in the bot task (it becomes an error)

I am following this procedure.Thank you.

1 Like

Thank you @hana can you please send the whole code here?
I couldn’t reproduce this issue.

Attach all source code.
Thank you very much.

<?xml version="1.0" encoding="UTF-8"?>
<config
	xmlns="http://web-harvest.sourceforge.net/schema/1.0/config"
	scriptlang="groovy">

	<robotics-flow>
		<robot driver="universal" close-on-completion="true"
			start-in-private="false">
			<capability name="SEARCH_ALL_WINDOWS" value="true" />
			<capability name="CLOSE_ALL_WINDOWS" value="false" />
			<script><![CDATA[
				import com.workfusion.studio.rpa.recorder.api.*
				import com.workfusion.studio.rpa.recorder.api.types.*
				import com.workfusion.studio.rpa.recorder.api.custom.*
				import com.workfusion.studio.rpa.recorder.api.internal.representation.*

				import com.workfusion.bot.exception.*

				def appear_flg = RBoolean.fromCanonical('false')

				def pass = workfusion_bot_task_service_registry.get(SecretsVault.class).findEntry('salesforce').map({ it.getValue() }).map({ RString.of(it) }).orElseThrow({ new SecretsVaultException("Secret Entry with alias 'salesforce' not found") })

				def window_title = RString.of('')

				def user = workfusion_bot_task_service_registry.get(SecretsVault.class).findEntry('salesforce').map({ it.getKey() }).map({ RString.of(it) }).orElseThrow({ new SecretsVaultException("Secret Entry with alias 'salesforce' not found") })

				com.workfusion.rpa.helpers.RPA.metaClass.static.$ = { Closure c -> c.call() } // Support for Expression action. Should be implemented in RPA class in next release.

				timeouts().pageLoadTimeout(20000, java.util.concurrent.TimeUnit.MILLISECONDS)

				openChrome(UrlOperations.ensureProtocol("https://playful-hawk-6h29zp-dev-ed.lightning.force.com/lightning/page/home"))

				window().maximize()

				$(byXpath("//*[@id=\"username\"]")).setValue(String.valueOf(user))

				$(byXpath("//*[@id=\"password\"]")).setValue(String.valueOf(pass))

				$(byXpath("//*[@id=\"Login\"]")).click()

				appear_flg = RBoolean.TRUE
				try {
					inDesktop {
						switchToExistingWindow(new WindowDescriptor("Chrome_WidgetWin_1", "\u30DB\u30FC\u30E0 | Salesforce - Google Chrome", false, false).toString(), 10000)
					}
				} catch (Exception i0) {
					appear_flg = RBoolean.FALSE
				}

				sleep(2000)

				$(byXpath("//*[@class=\'slds-icon\']")).click()

				inDesktop {
					sendKeys(StringTransformations.getKeyPressText(57424, 0, 40, 0))
				}

				inDesktop {
					sendKeys(StringTransformations.getKeyPressText(28, 13, 10, 0))
				}

				@CustomScriptAction(
				)

				def customScript() {
					driver().switchToLastWindow()
				}

				// Do not remove! Custom action customScript will be invoked here.
				customScripActionCall_customScript: {}

				sleep(3000)

				$(byXpath("//*[@id=\"split-left\"]/div/div/div/ul/li[5]/div/a")).click()

				$(byXpath("//*[@id=\"split-left\"]/div/div/div/ul/li[5]/ul/li[2]/div/a")).click()

				sleep(3000)

				putAt("appear_flg", appear_flg)
				putAt("window_title", window_title)
			]]></script>
		</robot>
	</robotics-flow>
	<export include-original-data="true">
		<single-column name="appear_flg"
			value="${appear_flg.toCanonicalRepresentation()}" />
		<single-column name="window_title"
			value="${window_title.toCanonicalRepresentation()}" />
	</export>

</config>

@hana sorry for the delay. I tried to reproduce this issue, but with no luck.

Thank you for reply.
Although this problem has not been solved, it does not matter if it can not be executed by the bot task.
I’ve resolved that I can’t click on the first element, so I’m going to close this thread.
Thank you for your response carefully.

Also thank you.

1 Like