Clicking OK in a Save As dialog

1,427 views
Skip to first unread message

Dan Sharp

unread,
Jan 3, 2015, 10:19:20 PM1/3/15
to watir-...@googlegroups.com
Hi!

I'm new to Watir... working on a script to automate some browser screen scraping.

One page in particular has this problem that I'm stuck on:  the page has a link that is a javascript link, and the result of the javascript is that it generates/sends a PDF to be downloaded/saved.  So when I use Watir to click the link, I get the Save As dialog, but I have no idea how to make it actually click the "OK" button in the Save As dialog. It's not a javascript window, so the usual javascript dialog/alert methods don't work.  Also, as the link is not a direct link to the PDF, I can't right-click on it to save it without the dialog.

I tried looking through the source to see if the URL was just hidden, but it's not... it appears to be generated via some convoluted javascript.

So I'm stuck. I can manually click the link and get the Save As dialog and manually click the "OK" button (I'm on a mac, using Firefox, if the matters).  But I can't automate it.

Any help?

Thanks!

-Dan

niartseoj

unread,
Jan 5, 2015, 1:16:07 PM1/5/15
to watir-...@googlegroups.com
see if browse..send_keys("{ENTER}") works for you...

Titus Fortner

unread,
Jan 5, 2015, 2:58:14 PM1/5/15
to watir-general

The problem with save as dialogs is that they are a part of the operating system,  not the browser. What you can do is set the browser profile to not check with the os when downloading.

Using profiles with watir -
http://watirwebdriver.com/firefox/
http://watirwebdriver.com/chrome/

Titus

--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Fleck

unread,
Jan 13, 2015, 3:14:21 PM1/13/15
to Watir General
So, I tried the example for firefox and i am still getting the dialog save window for our app.

I am attempting to download an excel file.  I enter the page click a button 'Show Download Link' then an 'Accept' button and lastly the link to download the file.  At this point the save dialog window opens...  Honestly I am only changing one thing from the example.

profile = Selenium::WebDriver::FireFox::Profile.new
profile['browser.download.dir'] = "/tmp/webdriver-downloads"
profile['browser.download.folderList'] = 2
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"

@browser = Watir::Browser.new :firefox, :profile => profile

I did notice the chrome explanation had a full list of profile options, is there one for firefox?

Titus, Dan, and anyone else have you been able to successfully prevent this dialog window from opening using this method?

Joe

Selenium Framework

unread,
Jan 14, 2015, 9:52:43 AM1/14/15
to watir-...@googlegroups.com
Here is an example of automatically downloading files in firefox (Navigate to section "Automatically download without file dialog")

Cheers!

Selenium Framework

unread,
Jan 14, 2015, 9:56:19 AM1/14/15
to watir-...@googlegroups.com
I was able to successfully download files with the below code [your code seems fine too]. Can you post the url which you are trying? maybe its not the code, but some other environment issue ?

Cheers
Reply all
Reply to author
Forward
0 new messages