0

When I try to get the src it returns None. The code should locate the image by its class name and get the attribute.

import selenium.webdriver as webdriver
import time
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()

url = ('https://www.instagram.com/cats')
driver.get(url)

time.sleep(3)

imgs = driver.find_element(By.CLASS_NAME, "_aagv").get_attribute("src")
print(imgs)

driver.quit()

enter image description here

I tired to use it with for loop as well but the results were same None. Any suggestions how to get it working?

2 Answers 2

1

You can get the value of the src attribute using the below locator:

time.sleep(3)
images = driver.find_elements(By.CSS_SELECTOR, "._aagv img")

for image in images:
    print(image.get_attribute("src"))
Sign up to request clarification or add additional context in comments.

1 Comment

That's the one I was looking into. It worked. Thanks @abisaran
0

The div class has the class that you are searching for ("_aagv"). You need to get the inner image element (<img>), because it is the element that has the src tag on it.

You could either change your selector to match the Image tag directly, or you could select Image tags inside of the <div> tag you matched.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.