Reputation: 13
I'm trying to get all the links of the images from the below mentioned html code type:
<a href="#!" class="elevatezoom-gallery" data-update="" data-image="https://img.xyz.com/rcmshopping/PROD_IMAGES/fffff_2018_05_10_10_49_23.jpg" data-zoom-image="https://img.xyz.com/rcmshopping/PROD_IMAGES/fffff_2018_05_10_10_49_23.jpg"> <img src="https://img.xyz.com/rcmshopping/PROD_IMAGES/fffff_2018_05_10_10_49_23.jpg"> </a>
I am not able to fetch any link from this part of html out f 3 any 1 is good for me. Im new to python please guide.
Upvotes: 1
Views: 244
Reputation: 193088
To print the value of the src attribute you have to induce WebDriverWait for the visibility_of_element_located()
and you can use either of the following Locator Strategies:
Using XPATH
:
print(WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[@class='elevatezoom-gallery']/img"))).get_attribute("src"))
Using CSS_SELECTOR
:
print(WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a.elevatezoom-gallery>img"))).get_attribute("src"))
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Upvotes: 1
Reputation: 2675
You can achieve that by using the find_elements_by_css_selector()
function.
links = self.webdriver.find_elements_by_css_selector('img[src="https://img.xyz.com/rcmshopping/PROD_IMAGES/fffff_2018_05_10_10_49_23.jpg"])
Upvotes: 0