driver.get("https://www.nasdaq.com/market-activity/stocks/screener")
try:
# Trying to click on 'Accept Cookies' if the footer banner appears
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='onetrust-accept-btn-handler']"))).click()
except: # else print the msg to console
print("No Cookie bar")
time.sleep(2) # a brief pause between two actions
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='nasdaq-screener__form-button--download ns-download-1' and contains(text(), 'Download CSV')]"))).click()
time.sleep(10) # wait for 10 seconds while the file is downloading
driver.close()