import time
from selenium import webdriver

DRIVER_PATH = "/home/michtang/selenium/chromedriver"
URL  = "https://www.newegg.ca/zotac-geforce-rtx-3080-zt-a30800d-10p/p/N82E16814500502"
# URL = "https://www.newegg.ca/samsung-860-evo-series-500gb/p/N82E16820147674?Item=N82E16820147674&cm_sp=Homepage_dailydeals-_-P0_20-147-674-_-02032021"
driver = webdriver.Chrome(DRIVER_PATH)
driver.get(URL)
time.sleep(3)
found = 0
timeWait = 100
buttons = driver.find_elements_by_class_name("btn")
# popup = driver.find_element_by_id("popup-close")
while found == 0:
    if buttons[0].get_attribute("innerText") == "OUT OF STOCK":
        print("OUT OF STOCK")
        while timeWait > 0:
            print("waiting to refesh in " + str(timeWait) )
            timeWait = timeWait - 1
            time.sleep(1)
        driver.refresh()
        buttons = driver.find_elements_by_class_name("btn")
        timeWait = 100
    else:
# fas = driver.find_elements_by_class_name("fas")
        found = 1
        print("found")

        # buttons[0].click()
print("done")
