簡體   English   中英

無法使用 Python Selenium 同時使用 Firefox 和 Chrome Webdriver 觸發按鈕

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

我需要在網站上抓取尺寸圖表圖像。 圖像放置在彈出窗口內。 我正在使用 Selenium、Python 來觸發 a href 並抓取數據。 我已附上我的代碼以供參考。

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

請幫助糾正這個問題。

由於某種機器人檢測,它不會運行 a.js 文件。 我通過禁用 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()

進口

from selenium.webdriver.chrome.options import Options

在此處輸入圖像描述

試試這個來找到元素並點擊那個特定的元素。

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