user3522371
user3522371

Reputation:

Selenium: How to locate all the images on a webpage without knowing their id or name attribute?

Let us say, I loaded a URI with selenium. I have no idea how the elements are named in that page (I do not know the id, name ... of elements). I want to download all the possible pictures that may exist on that webpage. This problem is solved through the first answer of this question. But how can I located with selenium all the pictures that exist on that webpage ?

I checked answers for similar questions like this one but the answers are not useful.

Upvotes: 0

Views: 2607

Answers (2)

Paul Harris
Paul Harris

Reputation: 5809

The easiest way is to find by tag name as all images will have an image tag you can just get every element on that page with that tag. In python i believe it will be using (note note find_element_by_tag_name as that would return just one of the elements)

find_elements_by_tag_name

and you will want to find elements with the img tag http://www.w3schools.com/tags/tag_img.asp

Upvotes: 1

Heaven42
Heaven42

Reputation: 329

If I'm not mistaken, you can do something like this

driver.find_element_by_tag_name('img')

Hope that's help.

Upvotes: 0

Related Questions