Using xPath selector to return src attribute from image

Hello,

I am trying to get the src attribute for an image, that is inside a table.
The table can have multiple rows, it is dynamic, and in each row there is always a text in the first column. Next to the text, there can be an image or not (2 different kind of images or ‘icons’).

I can do a foreach for every single row, but, since the image selector is not distinctive enough, I have not found any way to create the selector with the UiPath selectors, not getAttribute activities, because there is no way to tell if the row is the first one, second one, or whichever.

Now, I have found a way to make it work by creating a xPath, trying it out on the Google Chrome console. The XPath selector is the following one:

//span[contains(text(), ‘Y71A-234B3’)]/…/…/td[contains(@class, ‘general’)]/img[contains(concat(’ ', normalize-space(@src), ’ '), ‘resources/inc’)]/@src

As you can see from the xPath selector, “Y71A-234B3” is the row text, that would have to be passed as an input. As I said before, I have previously made a data scrapping from the website, and I am inserting every row text as an item to a collection (making sure not to repeat the elements). That is the reason why I just need to loop through the collection items now in a foreach, getting the src from the image in every iteration.

The issue is that I do not know how to get the expected result from the image in every iteration of the loop, since I have only made it work with an xPath.

Can you please tell me how to transform the xPath that was sent into a selector that is “understandable” by UiPath, for example, to a “css-selector”? How can I reference the “parent” using a css-selector, so that I can just reference the row name, then go up to the parent row, and go down again looking for the image in the HTML DOM? (the way I did it in the xPath).

Thank you.

depending on the details, as UiPath is generating additional attributes as well

We suggest to share with us a detailed description of the element structures. In general we do have the following options:

and would recommend to check more in details those options first

1 Like

Thank you for the help and the rapid response.

However, I have already tried the options that are mentioned in the Data Scraping link. The issue there is that with the data scraping tool, even if I select just one column (with 2 rows), it will provide the whole table in a single column, this way:

That is the reason why I am just getting the information I need, after getting the datatable, by looping through the datatable, getting the first item, and inserting it into a collection:

image

Moreover, the data, or the src in the image (which is the one that I need) is not shown in the data scraping or the extract wizard. This way, if I click on “extract correlated data” after getting all the information from the table, and select the image that I need (in multiple rows), I get the following error: “Please indicate fields that are correlated with the fields you indicated to define the first column”, even though the fields are exactly the same (the image in different rows).

image

I am also providing the table that I need to get the information from:

image

The images that I am refering to (that I would like to get the src attribute from) are the one that are shown before the numbers in the second and third row.

I am also providing the UI Explorer for the image selector, in case it is needed:



When it comes to the elements strcuture (in the website table, the HTML), there are multiple rows (tr), and some of them are empty. The ones that are not empty are the ones shown in the previous screenshots. Those rows (tr) have the following structure: the first column (td) is empty (not really, but it is no use for us); the second column may have the image that I am trying to get the information from, and the third column has the text that I would like to do the search from. I am also providing the HTML of this part so that you can see the DOM:
image

That is the reason why I would like to do it with the xPath selector, if possible, since I found that solution, but if there is any other possibility I’d really appreciate the help.

I will look further into the other options that were provided (find children and custom parsing).

Should you need anything else, please let me know. Thank you.

in the link, we explained how to change the attribute ( set to src)

From your screenshots we can see the tablerow attribute

here a full element structure sharing would help

1 Like

Thank you so much for the help. I didn’t realize about the tablerow attribute. The tablerow does not correlate with the row number (in the example it shows “7”, but it is actually the second row), so, what I did was get the tablerow from the text that is in the SPAN (since it cannot be a duplicate value), and then get the SRC attribute by passing the previous value as a variable in the “tableRow” attribute of the selector. That way it worked, and I could just add the value to a dictionary.

I will therefore mark your answer as the one that solved the topic. Thank you again.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.