Home > Software engineering >  how to click button and download a file using robot frame work or selenium, it not contains link
how to click button and download a file using robot frame work or selenium, it not contains link

Time:05-07

https://www.nasdaq.com/market-activity/stocks/screener - i need to download csv file from this site,

If solution in selenium or robot frame work both are fine. It is good to guide me with a reference code.

i was try this one, it is working 2 times per day -Trying to download a .csv from a website in python my requirement was unsuitable to this above one.

Also, i was work in selenium to, but it is deprecated and it is not work well -

from selenium.webdriver.common.keys import Keys
from selenium import webdriver

PATH = "E:/chromedriver_win32/chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.nasdaq.com/market-activity/stocks/screener") 
driver.implicitly_wait(10)
link = driver.find_element_by_class_name("nasdaq-screener__download")
link.click()
driver.close()

another method also i had tried, even though it is won't work

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
import time

options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
#driver.get("https://www.google.com")
page_url = "https://www.nasdaq.com/market-activity/stocks/screener"
driver.get(page_url)
time.sleep(5)
#driver.find_element(By.CLASS_NAME, "nasdaq-screener__form-button--download ns-download-1")
#kd = driver.find_element(By.ID, "onetrust-accept-btn-handler")
#kd.click()
title = driver.find_element(By.CLASS_NAME, "nasdaq-screener__form-button--download ns-download-2")
title.click()
driver.close()
#driver.close()

Both code are giving same error

error

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".nasdaq-screener__form-button--download ns-download-2"}
  (Session info: chrome=100.0.4896.127)
Stacktrace:
Backtrace:
    Ordinal0 [0x006D7413 2389011]
    Ordinal0 [0x00669F61 1941345]
    Ordinal0 [0x0055C658 837208]

CodePudding user response:

This should work:

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()

   

explicit wait imports (other than time)

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
  • Related