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>