Unable to extract data by using Xpath

Hi, I have a pdf text file and I am opening it in the browser and getting data using XPath. It is working fine if it contains in first page. Right now I have a 3-page pdf document and from the last document, I have to pick data using XPath. But it is giving me following error. Please do the needful.

Error executing WebElementAction
  com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=WebElementAction.ftl,id=21,name=Optional[WebElementAction],parent=-3,nextSibling=22,arguments=ActionArguments[varName=[amtexcluvat],exactMatch=[true],delay=[1000],useElementAttribute=[false],webElementLocatorType=[XPATH],xsi:type=[recorder:WebElementAction, recorder:WebElementAction],pollingInterval=[300],active=[true],actionDetails=[(get by /html/body/div[1]/div[2]/div[4]/div/div[3]/div[2]/span[114] xpath)],searchInFrames=[false],webElementLocator=[/html/body/div[1]/div[2]/div[4]/div/div[3]/div[2]/span[114]],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:64)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:152)
      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 locate element: /html/body/div[1]/div[2]/div[4]/div/div[3]/div[2]/span[114]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '9.2.0.4', revision: '1a10eeeced', time: '2018-11-29T10:44:59.891Z'
System info: host: '4L2H102', ip: '172.16.20.57', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{moz:profile=C:\Users\pritee.bhandari\AppData\Local\Temp\rust_mozprofile.JyoIMjrkuPHU, rotatable=false, moz:geckodriverVersion=0.22.0, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss and notify, strictFileInteractability=false, moz:headless=false, platform=XP, moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, acceptInsecureCerts=false, browserVersion=65.0.2, moz:shutdownTimeout=60000, platformVersion=6.1, moz:processID=11628, browserName=firefox, javascriptEnabled=true, platformName=XP, setWindowRect=true, moz:webdriverClick=true}]
Session ID: cc087a75-5b69-47aa-b7f4-c84e52d02a92
*** Element info: {Using=xpath, value=/html/body/div[1]/div[2]/div[4]/div/div[3]/div[2]/span[114]}
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.GeneratedMethodAccessor45.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 Script21.run(Script21.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:65)
      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:64)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:152)
      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 locate element: /html/body/div[1]/div[2]/div[4]/div/div[3]/div[2]/span[114]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '9.2.0.4', revision: '1a10eeeced', time: '2018-11-29T10:44:59.891Z'
System info: host: '4L2H102', ip: '172.16.20.57', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{moz:profile=C:\Users\pritee.bhandari\AppData\Local\Temp\rust_mozprofile.JyoIMjrkuPHU, rotatable=false, moz:geckodriverVersion=0.22.0, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss and notify, strictFileInteractability=false, moz:headless=false, platform=XP, moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, acceptInsecureCerts=false, browserVersion=65.0.2, moz:shutdownTimeout=60000, platformVersion=6.1, moz:processID=11628, browserName=firefox, javascriptEnabled=true, platformName=XP, setWindowRect=true, moz:webdriverClick=true}]
Session ID: cc087a75-5b69-47aa-b7f4-c84e52d02a92
*** Element info: {Using=xpath, value=/html/body/div[1]/div[2]/div[4]/div/div[3]/div[2]/span[114]}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '9.2.0.4', revision: '1a10eeeced', time: '2018-11-29T10:44:59.891Z'
System info: host: '4L2H102', ip: '172.16.20.57', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: driver.version: UniversalDriver
      at sun.reflect.GeneratedConstructorAccessor67.newInstance(Unknown Source)
      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:133)
      at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:205)
      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)

The bot cannot find the element by the XPath. Are you sure an element with such XPath exists on this page?

Hi @pbhandari

Please add a Scroll Mouse action and scroll to the third page (or the page where you need to get XPath). Then XPath should work fine. See the example below:
image

2 Likes