0

I am new to coding and I am trying to create a checkout bot. I am using selenium to help me do this. So far my code works up until the checkout I can't seem to get my bot to click the checkout button.

This is what I get when I inspect the checkout button.

   <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

I have tried

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']"))

None seems to work and doesn't click the checkout button. If any idea on how to fix this it would be helpful! Thank you :)

obotezat
  • 1,041
  • 16
  • 20
  • Are you getting an error? – Buddy Bob Apr 19 '21 at 05:09
  • @BuddyBobIII I am assuming so. I have it on a while loop that if checkout fails it will restart the program which is what's happening each time I get to checkout. I tried other buttons like Paypal and visa check out on the same page and they all were able to click just fine. – Jennifer Tsang Apr 19 '21 at 05:34

1 Answers1

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

Would click the a tag with the attribute continue to checkout. Now you might need to wait if you switch to that page or etc.

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()
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32