简体   繁体   中英

Can't trigger a button using Python Selenium using both Firefox and Chrome Webdriver

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.

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

在此处输入图像描述

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM