1

I'm trying to download pdf with clicking on Download button using selenium and python. But getting this above mentioned error while running Chrome and my full test developed for chrome browser.

driver.find_element_by_xpath("/html/body/app-root/app-full-layout/div/div[2]/div/div/div/app-list/section/div[2]/div/div[2]/div[2]/div/div[2]/button").click()
time.sleep(7)
options = Options()
options.set_preference("browser.download.folderList", 0)
options.set_preference("browser.download.manager.showWhenStarting", False)
options.set_preference("browser.download.dir", "/DFS")
options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/octet-stream,application/pdf")
driver = driver.Chrome(chrome_options=self.options)

Expected execute this code and download the pdf file

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
fakhrul
  • 27
  • 1
  • 7
  • You expect the code to run even when you reference a non-existing attribute? Or you expect `options` to have an attribute `set_preference`? Why is that? – Stop harming Monica Jun 12 '19 at 09:25

1 Answers1

2

selenium.webdriver.chrome.options Class doesn't include the method set_preference()

set_preference(name, value) is from the selenium.webdriver.firefox.options Class.

So while working with ChromeOptions for ChromeDriver and Chrome, you need to use add_argument(argument) method instead as follows:

options = webdriver.ChromeOptions()
options.add_argument("--safebrowsing-disable-download-protection")
options.add_argument("safebrowsing-disable-extension-blacklist")
driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')

You can find a relevant discussion in How to download XML files avoiding the popup This type of file may harm your computer through ChromeDriver and Chrome using Selenium in Python

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352