How to store href from image?

@admin @Plankton @ulrich

I need to store href (target url) from an image.

I tried without success store attribute

What can I store the href (url target destination) from an image ?

See image, i want to store href from my profile photo

Thanks

Storeattribute | //@[data-user-card=“newuserkantu”]@href | nom_variable

Seems storeattribute not working in image

Show this error

* [error][ignored]

[Line 1] missing attribute 'href'

I search a solution thanks

Which attribute do you want ? Href ? Src ?
Can you put tour command Line ?

This image element does not have a href attribute. Thus the RPA error message. But the element has a scr="…" value, so with the @scr attribute the link scraping works.

image

Test:

{
  "Name": "getlink",
  "CreationDate": "2020-11-2",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://forum.ui.vision/t/how-to-store-href-from-image/6398",
      "Value": ""
    },
    {
      "Command": "storeAttribute",
      "Target": "xpath=//*[@id=\"post_1\"]/div/div/a/img@src",
      "Value": "aa"
    },
    {
      "Command": "echo",
      "Target": "aa=${aa}",
      "Value": "green"
    }
  ]
}

You need a good advanced xpath because every image clickable have href but need a particular xpath to detect it (every clickable image have a href attribute)

More complex automations require advanced xpath like xpath axes, ui vision can not record these xpath types, need external tools.

https://www.w3schools.com/xml/xpath_axes.asp

There are numerous different types of xpaths but you don’t talk in this forum but they are very useful and allow you to do numerous advanced jobs that with a classic xpath you could not do. Ui vision recognizes only 10% of the xpaths available on one element, there is another 90% of different xpaths available advanced to perform complex automations.

Here the solution

Macro code:

{
  "Name": "StoreAttribute_Href_Image",
  "CreationDate": "2020-11-2",
  "Commands": [
    {
      "Command": "storeAttribute",
      "Target": "xpath=(//a[@data-user-card='newuserkantu']//img)[1]//parent::a@href",
      "Value": "Href"
    },
    {
      "Command": "echo",
      "Target": "Href In Image: ${Href}",
      "Value": "#shownotification"
    }
  ]
}

Log

* [status]

Playing macro StoreAttribute_Href_Image

* [info]

Executing: | storeAttribute | xpath=(//a[@data-user-card='newuserkantu']//img)[1]//parent::a@href | Href |

* [info]

Executing: | echo | Href In Image: ${Href} | #shownotification |

* [echo]

Href In Image: /u/newuserkantu

* [info]

Macro completed (Runtime 0.82s)

@newuserkantu Thanks for this very interesting post, I learned something new :slight_smile:

1 Like