1

everyone!

I'm using Python, Selenium and headless Chrome to simulate a button click to download a PDF file.

The problem is that the same exact piece of code with headless param works well for a button in certain page and it doesn't work for other page. About the page that doesn't work, if I take off the headless parameter, it works properly.

Here are my configs:

path = path+'/'+CPF_LOGIN
chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : path, "download.prompt_for_download": False}
chromeOptions.add_argument("--headless") 
chromeOptions.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chromeOptions)

driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': path}}
command_result = driver.execute("send_command", params)

driver.get(URL)

Here is when I perform the click with some javascript code:

element = WebDriverWait(driver, 30).until(
        EC.element_to_be_clickable((By.XPATH, '/html/body/ion-app/ng-component/ion-nav/page-splitpane/ion-split-pane/ion-nav/page-copasa-segundaviadecontadetalhe/ion-content/div[2]/div/ion-card/ion-card-content/div/button/span'))
    )

    time.sleep(10)
    driver.execute_script("arguments[0].click();", element)

It doesn't throw any exception. It simply doesn't download the file. Again, this same code with headless chrome config worked when I tried other button, in another page. In this page I'm facing the issue, if I take off the headless option, the download works.

Any thoughts?

Thanks.

anderici
  • 77
  • 1
  • 11

0 Answers0