Selecting a file in MacOS Finder when running Selenium / Capybara test script - automation

I'm attempting to upload a file on a page that I'm testing. The attach_file method within Capybara will not work here. The reason being that the upload feature is using a JS library named file-uploader here.
I'm actually able to invoke a mouse click in order to open a Finder window (in Mac OS) to allow me to select a file to open, however I'm not sure of how to work within this window. Essentially I'd like to select a file from my desktop and just click 'Open'.
Is there a way for me to work within this window to simply choose a file by its name and then click 'Open'?
I'm working in Firefox.
Dragging the file from my desktop into a div would also work, but I can not find a way to do that in Capybara either.
Thank you.

Selenium is a browser automation tool & as such any interaction with other components of operating systems is not possible. Once a browser opens a file open/Finder window, it's no longer the browser that you're interacting with. There are tools out there which can handle them, but i am not familiar enough to give a detailed response. Google the Robot framework, or AutoIt for starters.
Alternatively, since it's a JS library you're dealing with which handles the upload, you MAY be able to use the JavascriptExecutor to call library functions directly, which doesn't simulate the user experience, but may be enough to get past your hurdle.

Related

Selenium Automation + chromedriver

I am trying to automate a web application wherein clicking a link downloads a PDF file. The default behavior of chromedriver should open a pop-up window for confirmation. I am facing issue with the same, In my case the file is directly downloading without prompting.(I need to pop up to change the file name)
My understanding is that there is no easy way to make Selenium download files. Browsers use native dialogs which cannot be controlled by JavaScript.
Why are you downloading a file in the first place?
Check out this for more detail.
This can be set via settings option,
refer the below link https://support.google.com/chrome/answer/95574

How to handle Flash objects using Selenium Web Driver

How to handle Flash objects to perform some actions in my application. i am unable to identify the element. can any one help me for this issue
Selenium automates Web browsers.
From http://seleniumhq.org..
Selenium automates browsers. That's it.
Flash objects are impossible to automate using Selenium as flash objects are not technically 'browser driven' like javascript is. You'll have to find other software to automate Flash.
Source - I am a contributor / maintainer of the project.
If you are using Ruby language for Selenium-Webdriver automation then you can use "Gem SIKULI" using which we can deal with all Flash elements. http://rubygems.org/gems/sikuli
But it is not that much reliable.
Gem sikuli needs Jruby i.e Java+Ruby
Not possible. All you can do is do some clicking based on the coordinates, but this is really unreliable.
It is not possible to automate flash objects with selenium as selenium is only for HTML so you can use 3rd party API Sikuli for this purpose sikuli provides image based automation in which you take image of an object and then use that image as reference to perform your operation .So in other words in sikuli object identification is done via image processing
please check following simple blog posts to learn about usage of sikuli
Automating flash calculator with sikuli integration with selenium.
Add the flashdriver jar into your project and then use the FlashWebDriver method to operate the Flash file.

How to handle download dialog using Selenium IDE?

I have a web page which contains a download link. If I click on the link, download dialog window will be launched and asking save or cancel.
If I click on Save, file will get downloaded, it will be closed if I click on Cancel button.
But, Selenium IDE is capturing any actions performed in the dialog window.
Please tell how to handle this situation using Selenium IDE.
Thanks in advance.
Unfortunately save as dialogs cannot be interacted with via javascript so Selenium IDE can't manipulate them.
If you want to click on a link and download a file, you can set up Firefox to automatically save files (without dialog - http://kb.mozillazine.org/File_types_and_download_actions). At lease with this method you can save the file when running localy.
The limitation of this will be that if you wanted to export the selenese and run it on an external testing solution (Saucelabs or Testingbot) it is unlikely that this approach will work.
You can also modify the firefox profile in the setUp method of your test.
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword,application/csv,text/csv,application/rtf,application/xml,text/xml,application/octet-stream,application/vnd.ms-excel,application/zip,text/txt,text/plain,application/pdf,application/x-pdf");
If you have other types of documents you want to download you should look up the MIME type of whatever document you are trying to download and adding it to the comma delimited list.

Selenium- Issue-Clicking on windows pop-ups

I am using selenium to record some tests. We have a save to pdf button on our application that generates the windows open/ save or in firefox the ok/cancel windows pop up,
The issue is that i can;t get selenium to record my ok or cancel action since i think it is not a javascript window?
Does anyone know the command to do that?
thanks
Sadly, it's not possible to interact with such windows at the moment.
A good workaround for saving files dialog is to save the various parameters (local directory, etc) and tell your browser to not prompt for them, so the window won't pop at all.
See http://wiki.openqa.org/display/SEL/Selenium+Core+FAQ#SeleniumCoreFAQ-Whatyoucan%27tdowithSelenium
Create a separate firefox profile(command to open profile manager:-firefox -P) with the settings you want(you can give settings like where to download and save a file of a particular type automatically without prompting) and instruct your server to use that profile using the command : java -jar 'your server ' -firefoxProfileTemplate 'path_for_firefox_profile'

Control Download confirmation popup window using selenium script

I wrote test case to click on download button. How to go to download confirmation pop up window and select save or open option, and click ok and come back to main window. I am using selenium-python script for web test automation.
Selenium can't control the download confirmation. It can, however, type a file path directly in to the file upload field if you're using a "privileged" browser mode for IE or Firefox. If you're using the default *iexplore and *firefox modes with Selenium RC 1.0 beta 2, try simply type a file path directly in to the form field. I do this myself and it works great.
I think this question has been answered here before and the answer is using another tool for automating the browser's dialog e.g. autoit
How do we download a file by using Selenium?
you can switch the on the Pop-Up and confirm it, but I don't know to manage if....
Try that:
alert = browser.switch_to_alert()#switch to popup
alert.accept()#accept popup