1

What I am trying to do with RSelenium package is,

Step:1 Access a website - My own electric utility provider

Step:2 Access my account by explicitly providing my username and password (That's the reason I am unable to share the code)

Step:3 I click 'VIEW MY BILL'. The bill is displayed in pdf format.

Is there a way to download that file and save to specific folder? When I used download.file() command, it does not save the document, rather I get a 3KB pdf file that I am not able to open. Adobe Reader says that there is an error reading the document.

Possible method that I tried: 1. Right clicking, Pressing down arrow four times and then get to 'SAVE PAGE AS' click Enter.

But then it pops a dialog box asking for file name and location and I am not able to enter those details via RSelenium and save the file.

Example code: Some random PDF found online.

url<- "http://www.immigrationpolicy.org/sites/default/files/docs/how_us_immig_system_works.pdf"

setwd("C:/Users/king/Desktop/bill")
library(RSelenium)
library(downloader)
checkForServer()
startServer()
remDr <- remoteDriver()
remDr$open()
remDr$navigate(url)
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
Bharath
  • 1,600
  • 14
  • 25

1 Answers1

1

I found the answer on continuous research.

Firstly check whether Rtools is installed (Found the answer using this link)

Then updated my program

cprof<-makeFirefoxProfile(list(
  "pdfjs.disabled"=TRUE,
  "plugin.scan.plid.all" = FALSE,
  "plugin.scan.Acrobat" = "99.0",
  "browser.helperApps.neverAsk.saveToDisk"='application/pdf',
  ))
remDr <- remoteDriver(extraCapabilities=cprof)

Trying still to change the download folder which I am not able to find yet. I found the answer from THIS link

Kim
  • 4,080
  • 2
  • 30
  • 51
Bharath
  • 1,600
  • 14
  • 25
  • The above code worked only for the example in the question. When I tried the code in my actual application, the pdf file was autodownloaded as `.aspx` file. But then tried renaming the file as filename.pdf it worked. I renamed the downloaded file as .pdf. – Bharath Dec 27 '15 at 16:37