How to download any file using selenium webdriver. - selenium-webdriver

How to download any file using selenium webdriver.what is the logic to download any file in selenium webdriver

If you mean "any" file that browser would show, i.e. any html file, you just need to call
driver.getPageSource();
If you mean "any" file as in the "save link as" or similar menu of browsers you are out of luck, since this triggers the OS-driven download file chooser of a browser which can't be controlled by Selenium webdriver.
Solution to 2.
You have two options here I think:
a) use something like AutoIT ontop of selenium. This becomes very hard to control in a short time, is not portable and will make your tests error prone.
b) The better solution is probably to download the file outside of selenium. I found a nice article describing the whole dilemma here. It also contains a nice solution to the problem that takes even care of cookie-handling if needed for the download.

Actually it's not a good idea to download files using web-driver. I don't think that you need the file; in most cases, it's just for testing download links and for this purpose you can use driver.find_element_by_tag_name("a"), driver.find_elements_by_link_text("some text") or driver.find_elements_by_partial_link_text("a"); after finding the element, you just click() on it and check if the response's URL is actually what it should be.
Still if you have a goal for completely downloading the file, I'd be glad if you let me know.
EDIT:
Today, I visit this page and I think this will help you, specially this comment.

Related

print/print dialog validation by selenium Automation

Has anyone automated validating print/print dialog functionality output anytime?? or if any idea on the same please let me know here.
Thanks in advance.
Your question seems similar to the "File Open Dialog" problem.
My general remark in this case is as follows, when an external dialog (not inside HTML) called by the browser opens, the browser suspends communication with external scripts, including Selenium, until the operation that was called is performed.
In other words, run the AutoIt script first and then call the print dialog, never the other way around.

Playing a .mp4 file while writing it

This is a very simple task that I had such a hard time trying to do. My goal is pretty simple: send an mp4 file from my server to my client, and while its buffering and downloading I want to already play it. That means that I need to play a video.mp4 file while writing it, and I need it to display on some platform that I can control - like wxPython or WPF-Ironpython. Naturally, no such platform will let me play an open file for writing.
I have tried to implement and HTTP server (although totally unnecessary for my case, as I am writing an application-based Server-Client app) that would accept Range request, and when I run the server and load the URL on Chrome, it all works perfect and I can seek and buffering is great, but when I load it from WPF MediaElement it fails to play the video for some point (I cant really tell why as there is no documentation for this, any API, tutorials etc). I am really desperate.
I even thought about playing a video from a buffer and then just changing the buffer's content, but it doesn't seem like this possibility exists.
I am really stuck at this and I would love to get some suggestions. Please note that I am not a professional in this so I would appreciate if you could explain this to me in simple terms.
Thanks!
Not possible. MP4 is not the correct container for your application. You must use something like HLS/dash/fragmented MP4.

Using Selenium Commands on HTML content stored in a local varialble

This may sound odd BUT Is it possible to use WebDriver commands on a static variable that holds the html source? (eg: findElementbyId)
This is what i want to do:
set firefox webDriver
open website url
save the HTML pageSource to a "static local variable"
quit webDriver
Now - i want to be able to findElements and texts within this locally stored PageSource. (preferably using the selenium commands)
Any help and/or suggestion is greatly appreciated.
Thanks.
Basically no, it falls down at (5). The FirefoxDriver needs to communicate with an actual Firefox browser using the WebDriver protocol. Selenium can't work with just a String.
It's not clear what your use case is, but you could do things like copy the HTML to a temporary file, generate a file: URL for it, load it with the HtmlUnit or PhantomJS drivers and re-run your tests in-memory.
Surely plain old regular expressions, or an HTML parser like JSoup, are better options for post-processing HTML?

Automate download of file dynamically generated by http request

I am trying to automate the download of a bunch of csv files that are generated from a database based on which checkboxes are selected on a form. The website generates the csv file with the click of a 'Download' button. I found the URL to the download prompt using Firebug (and determined how it changes based on checkbox selection), but am unsure how to use it since it is dynamically generated and does not contain a file path. An example URL is the following:
https://www.quantcast.com/download/plannerCSV?&d0Id=10&sc=1&mr=10000
What is the best way to go about doing this? I looked into the Python mechanize module and briefly glazed over pydermonkey, but had trouble finding documentation on downloading dynamically generated files. I also found some suggestions on other forums for using VBscript and Perl-- I prefer to use Python if possible since I am most familiar with it, but if another language is more appropriate, I will learn what I need in order to accomplish this task--I just hope to do it efficiently! Comments from anyone with experience/knowledge/insight on this topic would be appreciated.
Probably the easiest way for you to do this is to use the command line tool wget. If running a UNIX/Linux it's already there. If you're running Windows then a Win32 version can can be downloaded from: http://gnuwin32.sourceforge.net/packages/wget.htm
The you can use a shell/batch script that will download the file for you.
Example for Windows:
set id=10
set sc=1
set mr=10000
set my_url=https://www.quantcast.com/download/plannerCSV?&d0Id=%id%&sc=%sc%&mr=%mr%
set filename=planner.csv
wget %my_url% --output-document=%filename%
:
: do stuff with file
:

Is there something similar for emacs like vims's NERDtree

For vim there is a filesystem explorer called NERDtree: https://github.com/scrooloose/nerdtree
Surely an alternative or superior package exists for Emacs?
I prefer dirtree (screenshot below) by Ye Wenbin. It feels pretty close to NERDTree / the TextMate drawer.
It took me a few minutes of trial and error to figure out the dependencies, so take a look at the install instructions (and a few minor edits to the source) I've got in this repo.
You can try NeoTree .
https://github.com/jaypei/emacs-neotree
Screenshot:
Have you looked at Speedbar ?
The Sunrise Commander seems to be a well written package, and it has a tree extension. For a screenshot of the tree extension in action, follow this link.
Who needs any tree, when you have the mighty ido-mode . If you can train your mind to find the files, rather than just your eyes whilst visually finding it, you will win. NO need to tell me how biology works, i don't care :-) you get the point.
Personally, I prefer the ECB's tree mode.
http://ecb.sourceforge.net/
You should also check out the CEDET stuff.
http://cedet.sourceforge.net/
They contain a lot of other useful stuff that you can use for similar development needs.
I use a little of emacs-nav and a little of dired to navigate my projects' file trees. For file management tasks, I mostly use bash (often from within emacs).
(Shameless reanswer from A good project tree browser for Emacs? - Stack Overflow)
I just now did a word search for "explore" in package-list-packages, and discovered project-explorer. Seems to fit exactly what I want today (I don't code hardly, but getting a grip on the structure of my Jekyll site).
Keys include TAB for folding and unfolding directories. Open files with RET or f, but with prefix, it will prompt nicely for which window, and even from there allow you to decide to use window or open up a new one to any side (I didn't find the prompt string in the package code, so it seems to leverage built in Emacs functionality nicely; indeed it looks like dired even).
It's available on Melpa and Marmalade, and packaged description points to sabof_project-explorer ยท GitHub.
I include the site's image for convenience:
I don't use projectile or helm, but it has some integration.
Try out lusty-explorer. It's a well done plugin.
Get it here

Resources