Error Retrieving href values with Xpath

xpath
web-element

#1

Hi all! I am trying to retrieve the values of the href tag using xpath. When I validate the xpath in Chrome’s Xpath Helper I do see the URLs. But when I use the same Xpath in RPA Express I receive the error below.

Please advice what I am doing wrong? Thank you in advance!

This is the Xpath I am using

Page: https://www.google.com/search?q=fruit
XPATH: //h3/a/@href

RESULT in Chrom Xpath Helper:
[https://nl.wikipedia.org/wiki/Lijst_van_fruit]
'https://nl.wikipedia.org/wiki/Fruit
'http://www.voedingscentrum.nl/encyclopedie/fruit.aspx
'https://www.plus.nl/producten/aardappelen-groente-fruit/fruit
'https://www.ah.nl/producten/aardappel-groente-fruit/fruit
'http://www.encyclo.nl/begrip/fruit
'https://www.schooltv.nl/video/nieuws-uit-de-natuur-fruit/
'https://www.schooltv.nl/video/bijen-in-de-knel-zonder-bijen-geen-groente-en-fruit/
'https://www.fruit.nl/

ERROR in WorkFusion:

Error executing WebElementAction
com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=WebElementAction.ftl,id=2,name=Optional[WebElementAction],parent=1,arguments=ActionArguments[varName=[rtitle],delay=[5000],useElementAttribute=[false],xsi:type=[recorder:WebElementAction, recorder:WebElementAction],pollingInterval=[300],active=[true],actionDetails=[(get by ${xpath} xpath)],searchInFrames=[false],xPath=[${xpath}],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:30)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:17)
at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:53)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:153)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:113)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.InvalidSelectorException: The given selector //h3/a/@href is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: The result of the xpath expression “//h3/a/@href” is: [object Attr]. It should be an element.
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: ‘8.4.5’, revision: ‘f4260441345d31500d1587ee0abfdfcd20e3a66a’, time: ‘2017-12-18 09:30:31’


#2

Hi Vladislav, you should use xpath //h3/a and use href in the attribute field as shown below.
It will save all titles’ URLs on the page to the variable.


#3

Does the same applies to text()? Because it is not working.
image


#4

Do you need to save the value of the element? In this case, I think you shouldn’t use an attribute, but if you do, don’t use the brackets.
Can you share the page url to check?


#5

Below is the URL. I can select the info in the description, next to bold text in the Xpath helper, but not in recorder.

Xpath: //span[@class=‘lot-description hidden-placeholder ng-binding’]/text()
URL: https://www.bva-auctions.com/v3/nl/auction/lot/32999/10747154?pid=1

I have tried using the text() attribute in the element window with and without the brackets. But it doesn’t work in any way.


#6

For some reason, the xpath only works with double quotes: //span[@class=“lot-description hidden-placeholder ng-binding”]


#7

I’ve just tried the below configuration but I still receive the NullPointerException error.
image

I have also tried using the text() attribute. Same error. Can you share your configuration?


#8

There is no text attribute in the tag, so it will not work. Just use the xpath.

This is weird, but now it has worked with single quotes: //span[@class=‘lot-description hidden-placeholder ng-binding’].