Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98822

Is there a more broad way to get the src in a webelement through selenium?

$
0
0

I have pulled 'src' from other webelements before however this one seems to elude me. I am trying to grab all the links to all the images on this webpage. However, even though the webelement is highlighted by a css selector, it does not return the link when I try to grab it through get_attribute('src'). I can achieve grabbing one image if I get specific with Xpath or Css Selector but I want to grab all (7 urls) of them at once and toss em into a list.

Any suggestions?

Here is my code:


from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.action_chains import ActionChains
from json import dumps, loads, JSONEncoder, JSONDecoder

import re
import json
import timeit
import time

start = timeit.default_timer()

driver = webdriver.Chrome()

wait = WebDriverWait(driver, 5)



def ImageFind():
    driver.get('https://shop.freedommobile.ca/devices/Apple/iPhone_11?sku=190199220546&planSku=Freedom%205GB')


    phoneImage = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, '.slide')))
    imageLink = phoneImage[0].get_attribute('src') #test for grabbing url for just one webelement

    print(len(phoneImage)) #check to make sure I have the right amount of elements being selected
    print(phoneImage) 
    print(imageLink)

    return imageLink


ImageFind()



Viewing all articles
Browse latest Browse all 98822

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>