You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpr_labscript.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python3
  2. import time
  3. from selenium import webdriver
  4. from selenium.webdriver.common.by import By
  5. def search_for_dress(driver, user_id):
  6. driver.maximize_window()
  7. url = f'https://{user_id}.cpr-akashop.com/'
  8. driver.get(url)
  9. time.sleep(1)
  10. # Find and click on the magnifying glass icon
  11. 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')
  12. magnifying_glass.click()
  13. time.sleep(1)
  14. # Find the search box and search for "dress"
  15. 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')
  16. search_box.send_keys('dress')
  17. search_box.submit()
  18. time.sleep(3)
  19. # Find and click on the Striped Dress search result
  20. striped_dress_link = driver.find_element(By.CSS_SELECTOR, '#post-82 > div > div > div > div.non-grid-content.alternative-layout-content > h2 > a')
  21. striped_dress_link.click()
  22. time.sleep(3)
  23. # Add the Striped Dress to the cart
  24. add_to_cart_button = driver.find_element(By.CSS_SELECTOR, '#product-82 > div.nv-single-product-top > div.summary.entry-summary > form > button')
  25. add_to_cart_button.click()
  26. time.sleep(3)
  27. # Click on View Cart
  28. view_cart_button = driver.find_element(By.CSS_SELECTOR, '#content > div > div > div > div.woocommerce-notices-wrapper > div > a')
  29. view_cart_button.click()
  30. time.sleep(3)
  31. # Click on Proceed to Checkout
  32. 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')
  33. proceed_to_checkout_button.click()
  34. time.sleep(3)
  35. driver.quit()
  36. if __name__ == "__main__":
  37. user_id = input("Please enter your user ID: ")
  38. # Chrome
  39. driver = webdriver.Chrome()
  40. search_for_dress(driver, user_id)