Problem with retrieving Xpath value

Hi Workfusion,

I have a problem with a bespoke system where I need to use Xpath reference to solve the task, however, I cannot get it to work.

I have uploaded the webdoc when I do inspect in Chrome so you can see the values and the first file show which element I select. This image is there twice but the secound is without the arrow pointing to the element … to ensure that you have the entire structure of the document.

Please help me understand why the Xpath value fails, see the following error message from Express Studio (2.4.0) just download today.

I use the following Xpath value //*[@id=“1”]/td[1] but it’s the same regardless which one I use.

Error executing MouseClickAction
com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=MouseClickAction.ftl,id=32,name=Optional[MouseClickAction],parent=21,nextSibling=33,arguments=ActionArguments[button=[1],delay=[0],exactMatch=[true],timeoutMs=[10000],webElementLocatorType=[XPATH],xsi:type=[recorder:MouseClickAction, recorder:MouseClickAction],pollingInterval=[300],active=[true],searchInFrames=[false],type=[WEB_ELEMENT],webElementLocator=[//[@id=“1”]/td[1]],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.NoSuchElementException: Unable to find element with xpath == //
[@id=“1”]/td[1]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘9.4.0.3’, revision: ‘abf2ebe0f1’, time: ‘2019-05-29T13:21:06.482Z’
System info: host: ‘ROBOT01’, ip: ‘10.81.8.250’, os.name: ‘Windows NT (unknown)’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{proxy=Proxy(), acceptInsecureCerts=false, browserVersion=11, se:ieOptions={nativeEvents=true, browserAttachTimeout=0, ie.ensureCleanSession=false, elementScrollBehavior=0, enablePersistentHover=false, ie.browserCommandLineSwitches=, ie.forceCreateProcessApi=false, requireWindowFocus=true, initialBrowserUrl=http://localhost:27323/, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, ignoreProtectedModeSettings=false}, timeouts={implicit=0, pageLoad=300000, script=30000}, browserName=internet explorer, pageLoadStrategy=normal, javascriptEnabled=true, platformName=XP, setWindowRect=true, platform=XP}]
Session ID: cb687c53-f3b4-486f-8af9-20dc1c62adef
*** Element info: {Using=xpath, value=//[@id=“1”]/td[1]}
Command duration or timeout: 0 milliseconds
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.findElement(RemoteWebDriver.java:446)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:548)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:438)
at com.workfusion.rpa.helpers.RPA.getElement(RPA.java:944)
at com.workfusion.rpa.helpers.RPA.$(RPA.java:864)
at sun.reflect.GeneratedMethodAccessor57.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:104)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:197)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:209)
at Script10.run(Script10.groovy:10)
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: org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //
[@id=“1”]/td[1]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘9.4.0.3’, revision: ‘abf2ebe0f1’, time: ‘2019-05-29T13:21:06.482Z’
System info: host: ‘ROBOT01’, ip: ‘10.81.8.250’, os.name: ‘Windows NT (unknown)’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{proxy=Proxy(), acceptInsecureCerts=false, browserVersion=11, se:ieOptions={nativeEvents=true, browserAttachTimeout=0, ie.ensureCleanSession=false, elementScrollBehavior=0, enablePersistentHover=false, ie.browserCommandLineSwitches=, ie.forceCreateProcessApi=false, requireWindowFocus=true, initialBrowserUrl=http://localhost:27323/, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, ignoreProtectedModeSettings=false}, timeouts={implicit=0, pageLoad=300000, script=30000}, browserName=internet explorer, pageLoadStrategy=normal, javascriptEnabled=true, platformName=XP, setWindowRect=true, platform=XP}]
Session ID: cb687c53-f3b4-486f-8af9-20dc1c62adef
*** Element info: {Using=xpath, value=//*[@id=“1”]/td[1]}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘9.4.0.4’, revision: ‘1fbe520b9b’, time: ‘2019-06-20T13:08:57.971Z’
System info: host: ‘ROBOT01’, ip: ‘10.81.8.250’, os.name: ‘Windows NT (unknown)’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: driver.version: UniversalDriver
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:186)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:121)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:50)
at org.openqa.selenium.remote.server.ActiveSessionCommandExecutor.execute(ActiveSessionCommandExecutor.java:43)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:741)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:446)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:548)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:438)
at com.workfusion.universal.driver.UniversalDriver.findElement(UniversalDriver.java:80)
at org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:48)
at org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:33)
at org.openqa.selenium.remote.server.handler.WebDriverHandler.handle(WebDriverHandler.java:41)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:134)
at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:206)
at org.openqa.selenium.remote.server.InMemorySession.execute(InMemorySession.java:98)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:231)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Have you checked this XPath in Developer Tools? Does it point to the element you need to save?

Hi Ashapkina,

Yes it point to the correct place, but regarless which element I select on the page then it does not work. When I look in the page I cannot see anything which should be a problem.

However, it’s a new windows that the system creates from the old one, can that cause the problem and how to get around that?

Best regards,
Michael Callisen

Do you mean the URL is opened in a new window?
In this case you need to switch to it using a custom action

Yes I use the std. web elements and click on a link which opens a new window. It’s is in this window that I have pasted the inspection code from and where I need to use Xpath to execute the logic.

Do you have an example on how to do that - then we will execute it. It’s very important that I can use Xpath otherwise it will not work.

Best regards,
Michael Callisen

@mc1 there are sample recordings in the topic I shared above. You can download them and copy the actions to your script.

Hi Ashapkina

You contant value does not work in the new version of Workfusion Express - the problem is the set value: ${driver().getWindowHandle()}

The custom action to swich windows works in you sample … tab2, but because of the problem with the ${driver().getWindowHandle()} you cannot get back to the original window.

@CustomScriptAction(
)

def customScript() {
switchToNextWindow()
}

However none of the above is working on my page - any suggestions?

I get the following error in the custom Action:

Error executing CustomScriptAction
com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=CustomScriptAction.ftl,id=32,name=Optional[CustomScriptAction],parent=21,nextSibling=33,arguments=ActionArguments[delay=[0],timeoutMs=[10000],xsi:type=[recorder:CustomScriptAction, recorder:CustomScriptAction],name=[switch browser window],pollingInterval=[300],active=[true],script=[@CustomScriptAction(
)

def customScript() {
switchToNextWindow()
}],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.NoSuchWindowException: Window is not defined yet. Please switch to some window before.
Build info: version: ‘9.4.0.3’, revision: ‘abf2ebe0f1’, time: ‘2019-05-29T13:21:06.482Z’
System info: host: ‘ROBOT01’, ip: ‘10.81.8.250’, os.name: ‘Windows NT (unknown)’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: driver.version: UniversalDriver
Command duration or timeout: 0 milliseconds
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.execute(RemoteWebDriver.java:798)
at org.openqa.selenium.remote.RemoteWebDriver.getWindowHandle(RemoteWebDriver.java:607)
at com.workfusion.rpa.driver.WindowNavigator.switchToNextWindow(WindowNavigator.java:58)
at com.freedomoss.crowdcontrol.webharvest.selenium.wrapper.RemoteDriverWrapper.switchToNextWindow(RemoteDriverWrapper.java:88)
at com.workfusion.rpa.helpers.RPA.switchToNextWindow(RPA.java:1210)
at com.workfusion.rpa.helpers.RPA$switchToNextWindow$3.callStatic(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:197)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:201)
at CustomScript_customScript.customScript(Script11.groovy:13)
at CustomScript_customScript$customScript.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 Script11.run(Script11.groovy)
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: org.openqa.selenium.NoSuchWindowException: Window is not defined yet. Please switch to some window before.
Build info: version: ‘9.4.0.3’, revision: ‘abf2ebe0f1’, time: ‘2019-05-29T13:21:06.482Z’
System info: host: ‘ROBOT01’, ip: ‘10.81.8.250’, os.name: ‘Windows NT (unknown)’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: driver.version: UniversalDriver
Build info: version: ‘9.4.0.4’, revision: ‘1fbe520b9b’, time: ‘2019-06-20T13:08:57.971Z’
System info: host: ‘ROBOT01’, ip: ‘10.81.8.250’, os.name: ‘Windows NT (unknown)’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: driver.version: UniversalDriver
at com.workfusion.autoit.driver.WindowManager.currentWindow(WindowManager.java:61)
at com.workfusion.autoit.driver.AutoItDriver.getWindowHandle(AutoItDriver.java:159)
at com.workfusion.universal.driver.UniversalDriver.getWindowHandle(UniversalDriver.java:115)
at org.openqa.selenium.remote.server.handler.GetCurrentWindowHandle.call(GetCurrentWindowHandle.java:14)
at org.openqa.selenium.remote.server.handler.GetCurrentWindowHandle.call(GetCurrentWindowHandle.java:5)
at org.openqa.selenium.remote.server.handler.WebDriverHandler.handle(WebDriverHandler.java:41)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:134)
at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:206)
at org.openqa.selenium.remote.server.InMemorySession.execute(InMemorySession.java:98)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:231)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

I have uploaded the corner of the Pop up window so you can see the type (IE)

Best regards,
Michael Callisen


@mc1 perhaps, the window load fully when you try to read the name? Try adding a timeout to the custom action.

Hi Ashapkina,
I tried that already

BR Michael