Rselenium - Popup

I want to download a file from a website using RSelenium with a Firefox browser. I am doing everything right (moving around, choosing the right element and writing down what I want); now I click on the “download” button, then a firefox popup window opens and asks if I want to download the file or “open with ...” something else.

Unfortunately, I cannot write an example due to privacy restrictions.

My question is: how can I switch to a popup / warning and click “OK” when necessary?

I tried the following methods without success:

remDrv$acceptAlert()     -> tells me: NoAlertOpenError  
remDrv$executeScript("driver.switchTo().alert().accept()")

I also tried the method

remDrv$getWindowHandles()

but even if the popup is open, the command returns me only one window (the initial one, not the popup), so I cannot use:

remDrv$switchToWindow()

to go to the popup.

Any ideas? Thanks

+4
1

, , , . JavaScript. Firefox . . , . , . . , :

require(RSelenium)
fprof <- makeFirefoxProfile(list(browser.download.dir = "C:\\temp"
                                 ,  browser.download.folderList = 2L
                                 , browser.download.manager.showWhenStarting = FALSE
                                 , browser.helperApps.neverAsk.saveToDisk = "application/zip"))
RSelenium::startServer()
remDr <- remoteDriver(extraCapabilities = fprof)
remDr$open(silent = TRUE)
remDr$navigate("https://www.chicagofed.org/applications/bhc_data/bhcdata_index.cfm")
# click year 2012
webElem <- remDr$findElement("name", "SelectedYear")
webElems <- webElem$findChildElements("css selector", "option")
webElems[[which(sapply(webElems, function(x){x$getElementText()}) == "2012" )]]$clickElement()

# click required quarter

webElem <- remDr$findElement("name", "SelectedQuarter")
Sys.sleep(1)
webElems <- webElem$findChildElements("css selector", "option")
webElems[[which(sapply(webElems, function(x){x$getElementText()}) == "4th Quarter" )]]$clickElement()

# click button

webElem <- remDr$findElement("id", "downloadDataFile")
webElem$clickElement()
+9

All Articles