python - Selenium/Python2.7 Find elements with similar src? -


from selenium import webdriver   fp = webdriver.firefoxprofile('') driver = webdriver.firefox(firefox_profile=fp) driver.set_window_size(1400, 1000) driver.get('')   list_of_elements = driver.find_elements_by_css_selector('img[title]') ele in list_of_elements:     print ele 

i'm trying print out img src=' ' of images on webpage, above code css selector , works same thing have code print out src links of images. im trying make list of elements on webpage based on src= , can search through src= , find 1 want. appreciated thanks!

looks interested in get_attribute():

srcs = [ele.get_attribute("src") ele in list_of_elements] 

note that, since going filter out elements based on src later - depending on how complicated check be, may solve single css selector. instance, let's want locate img element having title attribute , "test" inside src attribute:

driver.find_elements_by_css_selector('img[title][src*=test]') 

here *= means "contains".


Comments