0

I am trying to do a tutorial and learn Selenium in python however I cant seem to get Selenium to click the gif for continue checkout, I dont think you will be able to see the page unless you create an account etc so I will paste the html code in below

I am using:

  • Python v3.9
  • Chrome v87

This is the URL i am practicing on:

https://www.aria.co.uk/myAria/ShoppingBasket

Selenium code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

import time

# Open Chromedriver
driver = webdriver.Chrome(r"C:\Users\Ste1337\Desktop\chromedriver\chromedriver.exe")

# Open webpage
driver.get("https://www.aria.co.uk/SuperSpecials/Other+products/ASUS+ROG+Pugio+2+Wireless+Optical+RGB+Gaming+Mouse?productId=72427")
#https://www.aria.co.uk/Products/Components/Graphics+Cards/NVIDIA+GeForce/GeForce+RTX+3060+Ti/Palit+GeForce+RTX+3060+Ti+Dual+8GB+GPU?productId=73054

# Click "Add to Basket" or refresh page if out of stock
try:
    element = WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.XPATH, "Out of Stock!")))
    time.sleep(5)
    browser.refresh()
except:
    button = driver.find_element_by_id("addQuantityButton")
    button.click()

# Click basket
basket = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID, "basketContent")))
basket.click()

# Click checkout
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//img[contains(@src,'/static/images/checkoutv2.png')]"))).click()

# Login to account
login = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.NAME,"login[email]")))
login.send_keys("testuser@hotmail.co.uk")
login.send_keys(Keys.TAB)
driver.implicitly_wait(1)
passwrd = driver.find_element_by_xpath("/html/body/div[4]/div[1]/div[2]/form/div/h1/div[3]/div/div/input[2]")
passwrd.send_keys("password")
driver.implicitly_wait(1)
login.send_keys(Keys.ENTER)

# Click continue checkout
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[contains(@src,'/dynres/YnV0dG9uX3NtYWxsLm1lZGl1bQ==/Q29udGludWUgQ2hlY2tvdXQ=.gif')]"))).click()

HTML Code of the gif i need to click

<input type="hidden" name="addressID" value="940342">
<div style="text-align:right; margin-top:10px;">
    <input id="formSubmit" class="gaTrackedEvent" class="gaTrackedEvent" data-ga_event_category="checkout" data-ga_event_action="click_continue" data-ga_event_label="deliverydetails" type="image" src="/dynres/YnV0dG9uX3NtYWxsLm1lZGl1bQ==/Q29udGludWUgQ2hlY2tvdXQ=.gif" value="Continue Checkout">
</div>
</form>
</div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Stephen Brown
  • 53
  • 2
  • 7

3 Answers3

1

Have you tried its ID yet? Just making sure is all :) Class for "gaTrackedEvent" might work too. I need to see the rest of the HTML though to make sure there isnt more than one of the ID or Class name on the page.

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "formSubmit"))).click()
0

That xpath would fail.

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Continue Checkout']"))).click()

Also change password to

passwrd = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.NAME,"login[password]")))
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32
0

To click on the Continue Checkout gif element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.gaTrackedEvent#formSubmit[data-ga_event_category='checkout'][value='Continue Checkout']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='gaTrackedEvent' and @id='formSubmit'][@data-ga_event_category='checkout' and @value='Continue Checkout']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Sorry i should have added that i cant use gaTrackedEvent as it is also above in the code for a different html element – Stephen Brown Jan 19 '21 at 16:47
  • @StephenBrown The locators contains three other attributes other then `class="gaTrackedEvent"` so the locating strategy uniquely identifies the element. Can you get me the testing result? – undetected Selenium Jan 19 '21 at 17:09