0

I have got all the image tags by

image_tags = driver.find_elements_by_xpath('//img')

however, the src of the images needs some time to change to the format of 'https://....'. So here is what I got now

for image_tag in image_tags:
  WebDriverWait(driver, 60).until(** this image's src contains 'http' **) # how to write this part?
  url = image_tag.get_attribute('src') # get the real url address

Thanks!

3 Answers 3

0

OK, combine this answer [Create custom wait until condition in Python] with @OT413's answer, problem solved

 WebDriverWait(self.browser, 60).until(lambda wd: "http" in img_tag.get_attribute('src'))  
Sign up to request clarification or add additional context in comments.

Comments

0

You can use css selector and WebDriverWait to wait until img with src attribute begins with https:

image_tags = WebDriverWait(driver, 60).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "img[src^='https']")))
for image_tag in image_tags:
    print(image_tag.get_attribute("src"))

2 Comments

Can you illustrate what does "img[^='https']" mean please?
It should be img[src^='https']. img tag with src attribute begins with https, details here
-1

Try this:

  WebDriverWait(driver, 60).until("https://" in image_tag.get_attribute('src'))

1 Comment

Tried, not working. TypeError: 'bool' object is not callable

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.