I am trying to follow the code here. My code gives no error but it is not downloading file either. Below is my code:
def enable_download_headless(browser, download_dir):
browser.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir}}
browser.execute("send_command", params)
And this is the __main__
if __name__ == '__main__':
CHROME_PATH = '/chromedriver'
service = webdriver.chrome.service.Service(CHROME_PATH)
service.start()
options = webdriver.ChromeOptions()
# options.add_argument('--headless')
options.add_argument('--allow-insecure-localhost')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--allow-running-insecure-content')
# options.add_experimental_option("prefs", {'download.prompt_for_download': 'true'})
options.add_experimental_option("prefs", {
"download.default_directory": ".",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing_for_trusted_sources_enabled": False,
"safebrowsing.enabled": False
})
options = options.to_capabilities()
driver = webdriver.Remote(service.service_url, options)
driver.set_window_size(1400, 1000)
enable_download_headless(driver, ".")
driver.get("https://xx.xx.com/")
login()
# Go to the Dashboard
url = 'https://xx.xx.com/d/aa-xx'
driver.get(url)
sleep(5)
# btn_dl = driver.find_element_by_xpath('//*[@id="panel-c"]/button[2]')
# btn_dl = driver.find_element_by_css_selector('#panel-controls > button.sc-dkAroR.crYcIE')
btn_dl = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
(By.XPATH, "/html/body/div[2]/div[1]/div/div/div[2]/div/div/div[2]/div/div/div/div[1]/div[3]/button[2]")))
if btn_dl:
btn_dl.click() # It does not download