为什么Python Selenium单击按钮在Amazon上不起作用

2024-05-15 13:51:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让亚马逊商品买家,但有一个问题

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException


options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\QP\\AppData\\Local\\Google\\Chrome\\User Data")


driver = webdriver.Chrome(executable_path="C:\\webdrivers\\chromedriver.exe", chrome_options=options)
driver.get("https://www.amazon.com.tr/gp/product/9750748468?pf_rd_r=NCJRXGDB60BMBAWHZB0K&pf_rd_p=dbef927e-126e-4d59-a744-316eb26cc421&pd_rd_r=081be57a-efdb-4f6b-b282-72fb528b1bc5&pd_rd_w=Avc97&pd_rd_wg=XdzTG&ref_=pd_gw_unk")
try:
    element=driver.find_element_by_class_name("a-button-stack")
    element.click()
    print("Item found")
except NoSuchElementException:
    print("Item doesnt exist")

实际上,selenium找到了项,因为Exception不起作用,我在控制台上看到了“item found”,但element.click()不起作用。当我在另一个网站上执行相同的过程时,它可以正常工作


Tags: fromimportdriverseleniumrdelementchromeoptions