0

我是编码新手,我正在尝试创建一个结帐机器人。我正在使用硒来帮助我做到这一点。到目前为止,我的代码一直有效,直到结帐我似乎无法让我的机器人单击结帐按钮。

这是我检查结帐按钮时得到的。

   <a href="https://www.bestbuy.ca/identity/global/signin?redirectUrl=https%3A%2F%2Fwww.bestbuy.ca%2Fcheckout%2F%3Fqit%3D1%23%2Fen-ca%2Fshipping%2FON%2FM4W&lang=en-CA&contextId=checkout" class="button_E6SE9 primary_1oCqK continueToCheckout_3Dgpe regular_1jnnf" data-automation="continue-to-checkout"> == $0

我努力了

find_element_by_class_name("continueToCheckout_3Dgpe")
find_element_by_xpath( '//*[@class="continueToCheckout_3Dgpe"]' ).click()
findElement(By.cssSelector("a[href*='https://www.bestbuy.ca/identity/global/signin?redirectUrl=https%3A%2F%2Fwww.bestbuy.ca%2Fcheckout%2F%3Fqit%3D1%23%2Fen-ca%2Fshipping%2FON%2FM4W&lang=en-CA&contextId=checkout']")).click();
find_element_by_partial_link_text('https://www.bestbuy.ca/identity/global/signin?redirectUrl=https%3A%2F%2Fwww.bestbuy.ca%2Fcheckout%2F%3Fqit%3D1%23%2Fen-ca%2Fshipping%2FON%2FM4W&lang=en-CA&contextId=checkout')
find_element_by_xpath('//a[@href="https://www.bestbuy.ca/identity/global/signin?redirectUrl=https%3A%2F%2Fwww.bestbuy.ca%2Fcheckout%2F%3Fqit%3D1%23%2Fen-ca%2Fshipping%2FON%2FM4W&lang=en-CA&contextId=checkout"]')
find_element(By.xpath("//a[@href='https://www.bestbuy.ca/identity/global/signin?redirectUrl=https%3A%2F%2Fwww.bestbuy.ca%2Fcheckout%2F%3Fqit%3D1%23%2Fen-ca%2Fshipping%2FON%2FM4W&lang=en-CA&contextId=checkout']"))

似乎没有任何工作并且没有单击结帐按钮。如果对如何解决此问题有任何想法,那将很有帮助!谢谢 :)

4

1 回答 1

1
driver.find_element_by_xpath("//a[@data-automation='continue-to-checkout']").click()

将单击带有属性的标签继续结帐。现在,如果您切换到该页面等,您可能需要等待。

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//a[@data-automation='continue-to-checkout']"))).click()
于 2021-04-19T06:09:23.277 回答