Extract href attribute from a link not working

Given the following HTML:

<html>
	<body>
		<a href="test1.html">test1</a>
		<a href="test2.html">test2</a>
	</body>
</html>

I would expect

{
“Name”: “test”,
“CreationDate”: “2020-8-8”,
“Commands”: [
{
“Command”: “storeAttribute”,
“Target”: “xpath=/html/body/a[1]@href”, <---- relevant line
“Value”: “theLink”
},
{
“Command”: “echo”,
“Target”: “${theLink}”,
“Value”: “”
}
]
}

to give me “test1.html”, but instead I get an error:

  • [info] Executing: | storeAttribute | xpath=/html/body/a[1]@href | theLink |
  • [error][ignored] Line 1: timeout reached when looking for element ‘xpath=/html/body/a[1]’
  • [info] Executing: | echo | ${theLink} | |
  • [echo] #LNF

What am I doing wrong, how can I fix this?

Working this command you must add ( ) in xpath

Click solution button in this post please

Macro code fixed

{
“Name”: “Store_Attribute”,
“CreationDate”: “2020-8-8”,
“Commands”: [
{
“Command”: “bringBrowserToForeground”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “storeAttribute”,
“Target”: “xpath=(/html/body/a)[1]@href”,
“Value”: “theLink”
},
{
“Command”: “echo”,
“Target”: “${theLink}”,
“Value”: “#shownotification
}
]
}

Log

[status]

Playing macro Store_Attribute

[info]

Executing:  | bringBrowserToForeground |  |  | 

[info]

Executing:  | storeAttribute | xpath=(/html/body/a)[1]@href | theLink | 

[info]

Executing:  | echo | ${theLink} | #shownotification | 

[echo]

test1.html

[info]

Macro completed (Runtime 1.20s)

With braces the xpath works fine, thank you very much! Are these cases documented somewhere, how can one know that?

I found this using an addons for firefox called truepath this show all variants of xpath and in some xpath i see the ( ) I search best xpath with this addon.

xpath

1 Like

interesting, thank you!