5

using selenium 2 with webdriver one of my scripts needs to save a report in pdf or csv both just bring up a save as dialog. I do not know how to interact with it. im trying in firefox for now but would like to get it working in all browsers.

I read a few posts from 2009 that webDriver and selenium could not access save as dialogs but was wondering if there is a workaround floating around now.

I just need to click the save radio button so it does not try to open it then click the save button

ducati1212
  • 855
  • 9
  • 18
  • 29

4 Answers4

3

Only solution I know of is Firefox only. You can tweak the profile preferences to automatically download some MIME types to a directory of your choice. See my answer here.

Community
  • 1
  • 1
jarib
  • 6,028
  • 1
  • 24
  • 27
  • Seems like this would be a common enough problem to be high up on the todo list but I have seen threads going back 3 years on it. I hate having to use hacky work arounds in my stuff – ducati1212 Jan 19 '11 at 13:55
2

The problem with "SaveAs" and "File Open" dialog boxes is that they depend on the OS on which tests are being run and there is no means for selenium rc to interact with it. The only solution for this is to use some external Desktop Automation script like AutoIt to handle the dialogbox. Here's a good tutorial on how to do this.

Thanks,
Vamyip

vamyip
  • 1,161
  • 1
  • 10
  • 35
  • 2
    The OP is talking about WebDriver not RC so this feature should be possible. – Draemon Aug 13 '11 at 10:39
  • When it goes about desktop automation, For X11 - (for example Linux, but no only), you might be interested with : [xdotool by Jordan Sissel](http://www.semicomplete.com/projects/xdotool/), cause "tool lets you simulate keyboard input and mouse activity, move and resize windows, etc." – Grzegorz Wierzowiecki Sep 26 '11 at 09:34
0

Umm, if you are just interested in downloading a file, then you might prefer to manually download the file.

There are different reasons for using selenium, rather than http requests for automation, but a common one is to avoid messing around with javascript and cookies when logging in and navigating. If this is what you are interested in then then following code python code shows you how to reuse the cookies from selenium in order to fetch a url.

import requests
def fetch_url(driver, url):
    cookies = dict([(cookie['name'], cookie['value']) for cookie in    driver.get_cookies()])
    driver.get_cookies()
    return requests.get(url, cookies=cookies)

If you are interested in full stack testing it's a bit of a different story...

Att Righ
  • 1,439
  • 1
  • 16
  • 29
  • Good point, but downloading the URL outside the browser is an entirely different story. – Nemo May 07 '18 at 09:45
0

You can use sikulixapi for this open the dialog manually take a snipping tool (make sure you take a snip that will work on the expected resolutions otherwise sikuli won't find which sucks hopefully this will improve with time.). Then store it in a folder and this would be code you can use.

Pattern element = new Pattern(pathToImageString);
Screen screen = new Screen();
try{
    Match match =screen.wait(element);//if you want custom wait time (element,10.5)
    match.click();
}
catch(FindFailed findFailed){
    ..log failure
}
user2117229
  • 135
  • 3
  • 8