Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right click save as in RSelenium #60

Closed
thomasjwood opened this issue Nov 21, 2015 · 4 comments
Closed

Right click save as in RSelenium #60

thomasjwood opened this issue Nov 21, 2015 · 4 comments

Comments

@thomasjwood
Copy link

No luck on Stackoverflow so I'm trying here. This is such a straightforward application of the RSelenium package that I'm certain I'm missing something obvious.

I want to download a file whose link is generated on a webpage. The following code gets me 99% of the way there:

library(RSelenium)


RSelenium::checkForServer()
RSelenium::startServer()

eCap <- list(phantomjs.binary.path = "C:/Users/tom/Desktop/phantomjs.exe")

remDr <- remoteDriver(browserName = "phantomjs", 
                  extraCapabilities = eCap)

remDr$open()

remDr$navigate("http://www.fantasypros.com/nfl/rankings/wr.php")

xls_link <- remDr$findElement("css selector", 
                          "#export-xls")

remDr$mouseMoveToLocation(webElement = xls_link)

A screenshot demonstrates that the mouse has been located in the right place.

highlighted link on page

Why doesn't

remDr$click(2) # 2 indicates click the right mouse button
remDr$sendKeysToActiveElement(list(key = 'down_arrow',
                               key = 'down_arrow',
                               key = 'down_arrow',
                               key = 'down_arrow'))
remDr$click(1)

Initiate the "save as" dialogue? For that matter, why doesn't

remDr$click(1)

Download the *xlsx file?

@daigazi
Copy link

daigazi commented Dec 3, 2015

try below code

library(RCurl)
tmp=getBinalURL(url)
note=file("helloword.xlsx",open="wb")
writeBin(tmp,note)
class(note)

@johndharrison
Copy link
Member

PhantomJS doesn't currently support file downloads. Relevant issues with workarounds:

@AmeliaMN
Copy link

I'm not sure I'm following. I thought that remDr$click(2) was supposed to do a right click, but it does not. Is this because of PhantomJS? I've tried lots of variations, like remDr$click(buttonId = 2) and remDr$click('RIGHT'). Mostly I'm struggling to find documentation about this. Is there a good resource for general selenium documentation that would help with parameters here?

@Sebaristoteles
Copy link

I had issues using RCurl. The curl package is another option to download files like xls, png, etc.
Assuming you have set up your RSelenium instance as "remDr":

library(curl)
remDr$navigate("https://file-examples.com/index.php/sample-documents-download/sample-xls-download/")
element <- remDr$findElement(using = "xpath", "//*[contains(@download,'xls')]")
xls_link <- element$getElementAttribute("href")[[1]]
curl_download(url = xls_link, destfile = 'test.xls')  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants