How to retrieve data from the popup after clickable element trigger with WebDriverWait in Selenium Python?

不羁岁月 提交于 2021-01-29 05:20:53

问题


I need to scrape the image src from this popup. I have coded that but getting "AttributeError: 'NoneType' object has no attribute 'findElements'.

Here is the code.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from chromedriver_py import binary_path

import time
from time import sleep

url = 'https://www.macys.com/shop/product/black-tape-printed-contrast-trim-cardigan?ID=11398979&CategoryID=260&isDlp=true&swatchColor=Neutral%20Animal'

options = Options()
options.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=options, executable_path=binary_path)
wait = WebDriverWait(driver, 10)
driver.get(url)
sizechart_popup = wait.until(EC.element_to_be_clickable((By.XPATH, './/*[@class="sc-link"]'))).click()
sizechart = sizechart_popup.findElements(By.XPATH('.//*[@id="sizeImg"]/img')).get_attribute("src");

print(sizechart)

# Sleep of 10 seconds irrespective of whether element is present or not
time.sleep(50)
 
# Free up the resources
driver.close()

Thanks in advance


回答1:


Try using all the available element identifiers if one doesn't work, it worked with css_selector.

sizechart = driver.find_element_by_css_selector('#sizeImg > img').get_attribute("src")
print(sizechart)

#Output:
https://assets.macysassets.com/dyn_img/size_charts/4011861.gif


来源:https://stackoverflow.com/questions/65810010/how-to-retrieve-data-from-the-popup-after-clickable-element-trigger-with-webdriv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!