首页 > 解决方案 > 等到 WebElement 属性包含特定值

问题描述

我有所有的图像标签

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

但是,图像的 src 需要一些时间才能更改为“https://....”的格式。所以这就是我现在得到的

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

谢谢!

标签: pythonselenium

解决方案


好的,将这个答案[Create custom wait until condition in Python]与@OT413 的答案结合起来,问题解决了

 WebDriverWait(self.browser, 60).until(lambda wd: "http" in img_tag.get_attribute('src'))  

推荐阅读