from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import ElementNotInteractableException, NoSuchElementException, StaleElementReferenceException
from random import randint, randrange
#from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time
import random
BESTBUY_URL = 'https://www.bestbuy.com/site/sony-playstation-5-digital-edition-console/6430161.p?skuId=6430161'
BESTBUY_TEST_URL = 'https://www.bestbuy.com/site/sony-playstation-5-dualsense-wireless-controller-cosmic-red/6464309.p?skuId=6464309'
WAIT_TIME = 7
PRICE_LIMIT = 500
class Zac:
def __init__(self, username, password):
self.username = username
self.password = password
#binary = FirefoxBinary("/Applications/Firefox.app/Contents/MacOS/firefox-bin")
#self.driver = webdriver.Firefox("Applications/Firefox.app")
driver = webdriver.Chrome(executable_path="Applications/Google Chrome.app")
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
def signIn(self):
driver = self.driver
##Username
username_elem = driver.find_element_by_xpath("_____")
username_elem.clear()
username_elem.send_keys(self.username)
time.sleep(randint(int(WAIT_TIME/2), WAIT_TIME))
username_elem.send_keys(Keys.RETURN)
time.sleep(randint(int(WAIT_TIME/2), WAIT_TIME))
##Password
password_elem = driver.find_element_by_xpath("_____")
password_elem.clear()
password_elem.send_keys(self.password)
time.sleep(randint(int(WAIT_TIME/2), WAIT_TIME))
password_elem.send_keys(Keys.RETURN)
time.sleep(randint(int(WAIT_TIME/2), WAIT_TIME))
def findProduct(self):
driver = self.driver
driver.get(BESTBUY_TEST_URL)
time.sleep(randint(int(WAIT_TIME/2), WAIT_TIME))
isAvailable = self.isProductAvailable()
if isAvailable == 'Sold Out':
time.sleep(randint(int(WAIT_TIME/2), WAIT_TIME))
self.findProduct()
elif isAvailable <= PRICE_LIMIT:
buy_now = driver.find_by_name('submit.buy-now')
buy_now.click()
time.sleep(randint(int(WAIT_TIME/2), WAIT_TIME))
self.signIn()
##Place Order
place_order = driver.find_element_by_name('placeYourOrder1').text
time.sleep(randint(int(WAIT_TIME/2), WAIT_TIME))
## place_order.click()
## time.sleep(randict(int(WAIT_TIME/2), WAIT_TIME))
else:
time.sleep(randint(int(WAIT_TIME/2), WAIT_TIME))
self.findProduct()
def isProductAvailable(self):
driver = self.driver
available = driver.find_element_by_class_name('a-color-price').text
if available == 'Currently unavailable.':
print(f'***** AVAILABLE: {available}')
return available
else:
print(f'***** PRICE: {available}')
return float(available[1:]) ## $123.22 -> 123. 22
def closeBrowser(self):
self.driver.close()
if __name__ == '__main__':
shopBot = Zac(username="_____", password="_____")
shopBot.findProduct()
shopBot.closeBrowser()
For some reason, it is saying that Google Chrome.app executable needs to be in PATH. I am trying to make a scalping bot, and this seems to be my biggest mistake area. I am open to using any browser that is easiest. As you can see in the code I first tried this with FireFox. If anybody could help that would be greatly appreciated.