401.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import time
  2. from selenium import webdriver
  3. DRIVER_PATH = "/home/michtang/selenium/chromedriver"
  4. # Shining Fates ETB
  5. URL = "https://store.401games.ca/collections/pokemon-shining-fates-pre-orders/products/pokemon-shiningfates-elitetrainerboxpre-order"
  6. # Board Game Test
  7. # URL = "https://store.401games.ca/collections/pokemon-sealed-product/products/pokemon-battleacademyboxset"
  8. driver = webdriver.Chrome(DRIVER_PATH)
  9. driver.get(URL)
  10. time.sleep(3)
  11. found = 0
  12. timeWait = 100
  13. buttons = driver.find_elements_by_id("AddToCart-product-template")
  14. while found == 0:
  15. if buttons[0].get_attribute("innerText") == "SOLD OUT":
  16. print(buttons[0].text)
  17. while timeWait > 0:
  18. print("waiting to refesh in " + str(timeWait) )
  19. timeWait = timeWait - 1
  20. time.sleep(1)
  21. print("Time to refresh")
  22. driver.refresh()
  23. buttons = driver.find_elements_by_id("AddToCart-product-template")
  24. timeWait = 100
  25. else:
  26. found = 1
  27. print(buttons[0].text)
  28. quantity = driver.find_element_by_id("Quantity")
  29. quantity.clear()
  30. quantity.send_keys("10")
  31. buttons = driver.find_elements_by_id("AddToCart-product-template")
  32. buttons[0].click()
  33. time.sleep(3)
  34. cart = driver.find_elements_by_id("CartButton")
  35. cart[0].click()
  36. checkout = driver.find_element_by_xpath("//input[@name='checkout']")
  37. checkout.click()
  38. time.sleep(1)
  39. email = driver.find_element_by_xpath("//input[@name='customer[email]']")
  40. email.send_keys("michael.h.tang@gmail.com")
  41. password = driver.find_element_by_xpath("//input[@name='customer[password]']")
  42. print("done")