0

I need to scrape size chart image in a website. The image is placed inside a popup. I am using Selenium, Python to trigger the a href and scrape the data. I have attached my code for the reference.

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

import time
from time import sleep

url = 'https://www.macys.com/shop/product/jessica-howard-side-twist-sheath-dress?ID=11329706&CategoryID=5449'

driver = webdriver.Firefox()
driver.get(url)

#sizechart_popup = driver.find_elements_by_class_name('sc-link')
sizechart_popup = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, './/*[@class="sc-link"]'))).click()

print (sizechart_popup)

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

Please help to rectify this.

0

2 Answers 2

1

It doesn't run a .js file due to some kind of bot detection. I got it to open up by disabling navigator.webdriver.

options = Options()
options.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=options)
wait = WebDriverWait(driver, 10)
driver.get('https://www.macys.com/shop/product/jessica-howard-side-twist-sheath-dress?ID=11329706&CategoryID=5449')
wait.until(EC.element_to_be_clickable((By.XPATH, './/*[@class="sc-link"]'))).click()

Import

from selenium.webdriver.chrome.options import Options

enter image description here

Sign up to request clarification or add additional context in comments.

9 Comments

Thank you my friend. How to scrap image from the popup? I tried the following code. But doesn't work for me. sizechart_popup = wait.until(EC.element_to_be_clickable((By.XPATH, './/*[@class="sc-link"]'))).click() sizechart = sizechart_popup.find_element_by_xpath('.//*[@alt="size chart image"]') print(sizechart)
do you want the src? You'd have print(sizechart.get_attribute("src")) from it.
Yes My Friend, I need the image link
I got this kind of error - AttributeError: 'NoneType' object has no attribute 'get_attribute'
|
0

try this to find the element and perform click on that particular element.

WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@class="sc-link"]'))).click()

Comments

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.