I want to write a selenium program on a site which I need as part of the process to browse a file from the operating system. How can I do that?
If you mean to use Selenium to open a html file on local, it's easy to do.
1. open the html file on browser
2. copy the url in browser address, it should be like:
file:///C:/workspace/js-projects/tey/protractor-cucumber-tey/reports/cucumber_report.html
3. put above url in browser.get()
Better way it's to caclcute the html file absolute path in your scritp dynamically (rather than hard code), then prefix with file://// on the path, possible need to replace '\' to '/' in path.
I don't know what you mean by "browse a file from the operating system."
If you mean choosing file to upload, you can.
see link below
https://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.remote.LocalFileDetector
If you want to browse a file in the local machine with the OpenFileDialog (not sure if this is what you are looking for), in my case, I created an autoIt script, building it as .exe and then call it from Java code (or any programming language you are using with Selenium).
I found an exmaple, it might works: https://github.com/ellysh/autoit-examples/blob/master/Helpfile/FileOpenDialog.au3
Related
I'm trying to upload a file at Selenium IDE using relative path but it didn't work. I really tried some approachs like this answer
This way works:
But what I want to do is something like this:
I need it because I need to send these test files to run in another computer without have to edit the .side files. Anyone knows commands, scripts, or any other method that I could try at Selenium IDE?
Recently I made an application that has lots of PDF files in it and I made a setup for it using Inno Setup Compiler. In the setup, I allowed people to change where they want to install the app. For opening my PDF files, I used: system.diagnostics.process.start("My pdf.pdf")
My problem is that in the code above, I put drive "C:" and when my user changed the install directory to drive "D:" the pdf's did not work and the error showed that "Cannot find the specific file". My question is that is there a way to just put the name of "computer" or "a drive" in the code above, not the specific name of the pdf, and let the computer find the file itself?
You seem to be asking for an opposite of what you actually want to achieve.
I assume you are installing files with known names. What you do not know is the directory of the files.
From your description I assume that your actual code is like:
System.Diagnostics.Process.Start("C:\My pdf.pdf")
But when the user chooses a different location (directory) for your application, the above code with a hard-coded absolute path fails.
If your application installs to the same directory as the PDFs, just use a relative path (in this case just a file name without any path). It makes an operating system look to the current working directory, which will typically be an application directory.
System.Diagnostics.Process.Start("My pdf.pdf")
Or to make it more reliable, make it explicitly look to the application directory. For that use Application.StartupPath:
System.Diagnostics.Process.Start(
System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "My pdf.pdf"))
See also Get program path in VB.NET?
I have basic autorun.inf setup, which opens IE on client machine then tries to open html document located on cd/dvd within just opened IE.
Here it is:
open="C:\Program Files\Internet Explorer\iexplore.exe" index.html
Is it possible to pass somehow global variable or any other shortcut to lets say Program Files? It will be awesome if I could be sure that if user have different directories structure, still autorun will find out and open IE instead of doing nothing.
Try this:
[autorun]
open=start filepathname\index.html
Here is a question that looks like the answer you are looking for, please take a look:
How to make an html page open automatically on a CD/DVD
Hope it helps.
I am trying to use WinSCP to access a remote HTML file, and I do have root permission. However, if I open that HTML, it seems that all the sources and scripts are dysfunctional, e.g no images, buttons etc are loaded, and no js functions work. So how can I open a HTML using WinSCP so that all the sources are loaded and work properly? Thanks a lot.
I assume you "Open" the HTML file from a remote panel of WinSCP.
This makes WinSCP download the file to a temporary local folder and open the file from there.
As all the references to images and java script files are typically relative paths, they won't work from the temporary folder as the referenced files are not there. So it cannot work.
Either you need to download all files (including images and .js) to a local folder and open the HTML there.
Or you actually want to open the file from the server, via HTTP.
For that use the WinSCP extension "Generate HTTP URL".
I’m making a simple web browser for work eeh, what I’d like to know is if its possible to save a file of a particular extension to a particular file.
I currently use google chrome when downloading a file it places this (regardless of extension) in a downloads folder without asking where I ant to download this too.
I want to achieve the same except that downloads with the extension .dwg are placed automatically in a folder named DWG DOWNLOADS…
How to achieve this in vb.net?
In any browser you have a config section.
In Firefox you have browser.download.useDownloadDir;true and browser.download.folderList;1
you can add your own config to allow different saved folder paths and dynamically modify them depending on the extension of the file you uploaded.
See a complete list of the web browser config with about:config in address bar.
Not real sure what you are asking, but if you are actually making a web browser just check the extension of the file you are requesting to download. If the extension is ".dwg" then save the file to the folder you want.
If you are wanting to automatically move Google Chrome downloads to a different directory, you can use a FileSystemWatcher to monitor for new files in Chrome's download directory and move them to another folder based on each file's extension.