I want to download a file from a website. In the website I click on a button that opens a small sub-window, which has a button that downloads a file to the directory path_here
when clicked. This is my solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--dns-prefetch-disable')
chrome_options.add_experimental_option("prefs", {
"download.default_directory": r'path_here',
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
driver = webdriver.Chrome("./chromedriver", options=chrome_options)
website = "https://www.chess.com/ccc"
driver.get(website) # loads the page
# This closes a sub-window that opens automatically
element = driver.find_element_by_class_name("form-button-component")
element.click()
driver.find_element_by_class_name("icon-download").click()
download = driver.find_element_by_class_name('download-pgn')
# Click to download
download.find_element_by_class_name("btn").click()
This should work, but does not download the file, as I expected. I add a screenshot for completeness:
The button is Download Game (PGN), whose text is obtained by print(download.find_element_by_class_name("btn").text)