1

So I am trying to automate to preorder the ps5 but the issue is the preorder button vanishes if its out of stock. this code is throwing NoSuchElementException. I am trying to refresh the page until the button appears

import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.common.exceptions import NoSuchElementException

driver = webdriver.Chrome(r"C:\Program Files\chromedriver.exe")
driver.get(someWebsite)
buttonPresent = False

while not buttonPresent:
    if driver.find_element_by_id("buy-now-button") == selenium.common.exceptions.NoSuchElementException:
        driver.refresh()

    else:
        driver.find_element_by_id("buy-now-button").click()
        buttonPresent = True

0 Answers0