ROBOTFRAMEWORK - Looping through all images on a page - pulling the link

Viewed 24

I am working on a test that checks that all images on a page are visible. I'm running into an issue where its only pulling the link from the first img on the page and logs it the length of the loop. Im currently getting a count of all the images, and in that count I loop through and pull the img source. There are no special classes, or ids. The only thing I have to go off of is . I'm guessing I will somehow need to parse the entire HTML since robotframework only looks at what is viewable on the screen?

My end goal is to pull all img sources on a page and confirm each one returns a 200 status code.

Here is what I have now:

@{all_image_sources}    Create List
    ${all_images}  Get Element Count  //body//img
    FOR  ${image}  IN RANGE  ${all_images}
        ${img_src}  Get Element Attribute  tag:img  src
        log  ${img_src}
        Append To List  ${all_image_sources}  ${img_src}
    END
    Log List    ${all_image_sources}'''
1 Answers

You might consider using Get WebElements, this will give you each image locator in a list. You can then loop through the list to get each src attribute.

example:

@{all_image_sources}    Create List
${all_images}  Get WebElements  //body//img

FOR  ${image}  IN  @{all_images}
    ${img_src}  Get Element Attribute  ${image}  src
    Append To List  ${all_image_sources}  ${img_src}
END
Log List    ${all_image_sources}

Get WebElements

Related