Keir
Keir

Reputation: 607

chromeOptions.add_experimental_option no such attribute

I wish to do a direct download of a PDF and not display in Chrome's pdf view plugin The Python code I found is

chromeOptions = webdriver.ChromeOptions()
prefs = {"plugins.plugins_disabled" : ["Chrome PDF Viewer"]}
chromeOptions.add_experimental_option("prefs",prefs)
driver=webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', chrome_options=chromeOptions)

chromeOptions does not have an add_experimental_option function/methodP. Is there a way to make this work please.

Upvotes: 0

Views: 3259

Answers (2)

Keir
Keir

Reputation: 607

For whatever reason the method add_experimental_option does not appear. Possibly this is because I am using a Linux install. My goal is to download a series of PDFs automatically. A work around is to first get the PDF in the pdf-viewer by finding a web element with the click() command. this loads the PDF into the viewer, then read the contents of the URL bar, the use the PDF address to make a call to the Linux operating system running the dowload command "wget" to obtain the PDF file. That is:

driver.find_element_by_class_name('browzine-direct-to-pdf-link').click()
pdfAddress=driver.current_url
os.system("wget %s -P /home/keir/Downloads/pdfs" % pdfAddress)

Upvotes: 0

Brice Frisco
Brice Frisco

Reputation: 450

Here is the proper way to initialize chrome options:

from selenium.webdriver.chrome.options import Options
chrome_options = Options()

I believe that is your issue. I tested this code and it worked for me:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
prefs = {"plugins.plugins_disabled" : ["Chrome PDF Viewer"]}
chrome_options.add_experimental_option("prefs",prefs)
driver=webdriver.Chrome(chrome_options=chrome_options)

For more information you can read the docs here regarding the Chrome WebDriver API for Selenium

Upvotes: 2

Related Questions