I had a bit of coding I did last month, and I returned to it today to find that the same function was now returning an empty 'src' when I ran the code. I'm supremely baffled as to what changed.
My relevant code:
from selenium import webdriver
driver = webdriver.Chrome('/Users/jones/Downloads/chromedriver')
driver.get('https://www.linkedin.com/in/pauljgarner/')
images=driver.find_elements_by_xpath('//img[@id="ember1216"] | //img[@id="ember1808"]')
sleep(5)
for image in images:
print(images.get_attribute('src'))
url = images.get_attribute('src')
I saw some posts that suggested the issue was that I needed the page to fully load and insert coding that has an implicit or explicit wait time. However, I did the code line by line in ipython, so the timing cannot be the issue -- the src was still returning a null.
Any idea of what is happening here? I know that there is an image, and that my xpath is correct. So, there must be a relevant src.
Change images to image inside your loop.
for image in images:
print(image.get_attribute('src'))
url = image.get_attribute('src')
But looking at the page html, I was not able to find any elements with an img tag with the id's that you are trying to use. Which images are you trying to find?