Use css-selector to find all images in a webpage

Hello, I’m trying to save the 10 images from that site: https://www.copart.ca/lot/24643739/Photos

I managed to did it using ‘Find Children’ and then looping in it with another ‘Find Children’. it’s look totally horrible, I would like to actually find all the images directly, using a css-selector and then save them 1 by 1.

Here what I did (Can’t upload as I’m a new user…) : Main.xaml - Google Drive

Here the css-selector that I tried to use:

< html app=‘chrome.exe’ />
< webctrl css-selector=‘.viewAllPhotosRelative .img-responsive’ />

Anyone got a solution?

@MaxyArthes You could use Inject JS Script activity to do this.

// JavaScript Function
function getImageUrls() {
        var imageClasses = document.getElementsByClassName('viewAllPhotosRelative');
        var imageUrls = [];
        for (var index = 0; index < imageClasses.length; index++) {
            var element = imageClasses[index].getElementsByTagName('img')[0];
            imageUrls.push(element.getAttribute('src'));
        }
        return imageUrls;
    }

Use Inject JS Script activity with the above code. You can get all the image URLs in a comma separated string and use string activities to get individual image URL.

Sample flow.

getImageUrls.zip (1.9 KB)

For guidance only. Do not use as such.

Insert JS Script Documentation

Please mark this post as solution if it helped.

1 Like

does that work only with IE? Tried on Chrome with no result

I did this with IE. Chrome should also work. But you need to change the browser settings in the code.

Source: Inject Js Script ‘chrome.exe Chrome’

Message: Cannot find the UI element corresponding to this selector: < html title=‘Damaged Car Auction*’ />< webctrl css-selector=‘html>body’ id=‘mainBody’ tag=‘BODY’ />

Exception Type: UiPath.Core.SelectorNotFoundException

That what I’m getting with Chrome, any idea? Tried to edit the selector and stuff but still getting error

Try any other selector.

Source: Inject Js Script ‘chrome.exe Chrome’

Message: Error HRESULT E_FAIL has been returned from a call to a COM component.

Exception Type: UiPath.Core.ElementOperationException

Tried that too and I’m getting this error if I play with the selector, tried to select a part of the page and the whole browser too, both had the same result =/

The flow I shared is working fine for me. I inserted the JS in the main body tag. Did you try with IE?

Tried but I got a error that its can’t communicate with IE and I got a recent .net version installed