简体   繁体   English

无法使用 Python Selenium 同时使用 Firefox 和 Chrome Webdriver 触发按钮

[英]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.我正在使用 Selenium、Python 来触发 a href 并抓取数据。 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.由于某种机器人检测,它不会运行 a.js 文件。 I got it to open up by disabling navigator.webdriver.我通过禁用 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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