1

There's a lot on this topic. However, I have found nothing workable so far that involves using what is said in the title above and configurations listed below.

Here is what I am attempting to do: go to this webpage and click on the csv document icon for download (via xpath or css selectors). Either icon is fine - they download the same content.

The sourcecode below outlines what I have done so far. This script runs with no issues, but no document is downloaded - how do I possibly resolve this issue?

Note the following parameters for OS, Python, ChromeDriver, and Chrome configurations:

macOS Mojave v.10.14.6, Python v.3.7.3, ChromeDriver v.770386540, Chrome v.770386540

from selenium import webdriver

options = webdriver.ChromeOptions()

prefs = {"download.default_directory": "SOME_PATH"}
options.add_experimental_option("prefs", prefs)
options.binary_location = 'PATH_TO_CHROME'
options.add_argument('headless')

# set the window size
options.add_argument('window-size=1200x600')

# initialize the driver
driver = webdriver.Chrome('PATH_TO_CHROME_DRIVER',
                          options=options)

page_url = 'http://webapps.rrc.texas.gov/eds/eds_searchUic.xhtml'
button = '//*[@id="SearchUicForm:searchTable_paginator_top"]/a[7]'

driver.get(page_url)

# wait up to 10 seconds for the elements to become available
driver.implicitly_wait(5)

driver.find_element_by_xpath(button).click()
nate
  • 440
  • 2
  • 8
  • 18

1 Answers1

2

You can comment this line of code options.add_argument('headless') and see what is happening in browser. It basically clicks the cvs icon and a download window pop up in browser so we need to handle this pop up window in order to download. We can add chrome options to prevent this.

options = Options()
options.add_experimental_option("prefs", {
  "download.default_directory": r"C:\Users\xxx\downloads\Test",
  "download.prompt_for_download": False,
  "download.directory_upgrade": True,
  "safebrowsing.enabled": True
})
driver = webdriver.Chrome(chrome_options=options)
Mert Köklü
  • 2,183
  • 2
  • 16
  • 20
  • I haven't tested yet but if it doesn't work and using Firefox won't be a problem then see my other tested answer [my stackoverflow answer](https://stackoverflow.com/a/58271062/10515117) – Mert Köklü Oct 13 '19 at 19:28
  • thanks for the input but "AddUserProfilePreference" is not a method - is there some other functionality you may be referring to? – nate Oct 13 '19 at 19:38
  • 1
    I have edited the answer for python. Sorry for not focusing on language. – Mert Köklü Oct 13 '19 at 19:42