#!/usr/bin/env python3 import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service as ChromeService from selenium.webdriver.chrome.options import Options from webdriver_manager.chrome import ChromeDriverManager def search_for_dress(driver, user_id): url = f'https://{user_id}.cpr-akashop.com/' driver.get(url) print(f"Navigated to {url}") time.sleep(1) # Find and click on the magnifying glass icon magnifying_glass = driver.find_element(By.CSS_SELECTOR, '#header-grid > nav.header--row.header-main.hide-on-mobile.hide-on-tablet.layout-full-contained.nv-navbar.header--row > div > div > div > div.hfg-slot.right > div > div.item--inner.builder-item--header_search_responsive > div > div > a > svg') magnifying_glass.click() print("Clicked on magnifying glass icon") time.sleep(1) # Find the search box and search for "dress" search_box = driver.find_element(By.CSS_SELECTOR, '#header-grid > nav.header--row.header-main.hide-on-mobile.hide-on-tablet.layout-full-contained.nv-navbar.header--row > div > div > div > div.hfg-slot.right > div > div.item--inner.builder-item--header_search_responsive > div > div > div > div.form-wrap > form > input') search_box.send_keys('dress') search_box.submit() print("Searched for 'dress'") time.sleep(3) # Find and click on the Striped Dress search result striped_dress_link = driver.find_element(By.CSS_SELECTOR, '#post-82 > div > div > div > div.non-grid-content.alternative-layout-content > h2 > a') # Scroll to the element driver.execute_script("arguments[0].scrollIntoView(true);", striped_dress_link) time.sleep(1) # Add a small delay after scrolling striped_dress_link.click() print("Clicked on the Striped Dress link") time.sleep(3) # Add the Striped Dress to the cart add_to_cart_button = driver.find_element(By.CSS_SELECTOR, '#product-82 > div.nv-single-product-top > div.summary.entry-summary > form > button') add_to_cart_button.click() print("Added Striped Dress to the cart") time.sleep(3) # Click on View Cart view_cart_button = driver.find_element(By.CSS_SELECTOR, '#content > div > div > div > div.woocommerce-notices-wrapper > div > a') view_cart_button.click() print("Clicked on View Cart") time.sleep(3) # Scroll to the Proceed to Checkout button proceed_to_checkout_button = driver.find_element(By.CSS_SELECTOR, '#content > div > div > div > div.nv-content-wrap.entry-content > div > div.cart-collaterals > div > div > a') driver.execute_script("arguments[0].scrollIntoView(true);", proceed_to_checkout_button) time.sleep(1) # Add a small delay after scrolling # Click on Proceed to Checkout proceed_to_checkout_button.click() print("Clicked on Proceed to Checkout") time.sleep(3) def main(user_id): # Set up Chrome options chrome_options = Options() chrome_options.add_argument("--headless") # Run headless Chrome chrome_options.add_argument("--disable-gpu") # Disable GPU acceleration chrome_options.add_argument("--window-size=1920,1200") # Set window size to avoid issues with elements being out of view # Use WebDriverManager to automatically manage the ChromeDriver installation service = ChromeService(ChromeDriverManager().install()) driver = webdriver.Chrome(service=service, options=chrome_options) search_for_dress(driver, user_id) driver.quit() print("Browser closed") if __name__ == "__main__": user_id = input("Please enter your user ID: ") # Ask for the user ID only once main(user_id)