Upload and download files with buttons using cURL (or other....) - bash

I would like to know how to use in bash in order to first chose some parameters on a internet page then upload a *.txt file, and be redirected(after file analysis) to an other page and finally to press on a button to download a new file all this in bash.
I found a lot of information on forums regarding cURL and how to fill in forms and download files but very often you could juste download the file by accessing with URL/file.txt. Here it seems to me that it is different because the page uses some code in order to analyse my .txt file and output a new one.
The site is MSC server and I need to check the CADD checkbox in option 2, upload a *.txt by choosing file, click on upload & submit and after beeing redirected click on download result. Here is the html important parts
first page:
<form action="UploadServlet" method="post" enctype="multipart/form-data">
Apply MSC to: <input TYPE=checkbox name=measure1 VALUE=CADD> CADD 1.3
<input type="file" name="fname" id="fileChooser" size="16" /><br>
<input type="submit" value="Upload & Submit" size="20" onclick="document.getElementById('pleaseWait2').style.display = 'block';"/>
second page:
<form action="DownloadServlet" method="post">
<input type="submit" value="Download Result" color ="#ff0000" size = 200>
That is what I tried
curl -L -F measure1=CADD -F fname=#file2.txt -F submit="Upload & Submit" http://pec630.rockefeller.edu/MSC/
That was what I tried for the first page but it only shows me on the terminal the HTML code of the same page not the one where I should be redirected. And even if it gives me teh HTML of the second page, I've got no idea on how to download the file, firstly because the URL changes so I don't know what to put for the URL (I think it's something with cookies but I'm not sure) and secondly even when I try to click on a button and to download a file (for example, ont the example button on the first page, it still shows me the HTML code and it doesn't download the text file).
I hope I was clear enough and that you will be able to help me, I'm still a beginner in programmation and It's been 10 hours since I started to find how to do this:/.
Also since it's my first question (I normally always find previous questions that were like mine) I take this opportunity to thank you are all because your answers are always very clear, and I hope I'll be able to help other people to when I'll understand more of what I do :)

I didn't found the kind code I was looking for (I suppose it is a problem with cookies but even when I tried to handle them with cURL it is not working) but I found a way to get around "any" (I think) cURl problems. Maybe it will help others:
Just copy the headers your computer sends to the site as you a doing what you want:
in google chrome
view -> developer -> developer tools -> do what you want to -> right click on the name which pops up in the side bar -> copy as cURL -> paste it in your code
It's certainly not the best way to do it but if you're desperate as I was it works:)

Related

How to download from mail

Denar All!
I tried to add to my mail download attribute to download a picture to recipient pc/cell Phone, (right Click, inspect code, Edit html), and it accepts simple codes to "play with", but it just ignores 3 line w3schools code with download attribute. Do I Use the wrong pc or wrong doma in and what should it be like?
Just to add, I tried both options: with an internet photo/seems this would not work either, and with the picture from my own pc. For easy peasy code no result at all, makes me already desperated, is anyone willing to help, thanks in advance!
Using Chrome 84
This is most likely a cross-domain or local resource issue. You can verify this by going to DevTools (Menu -> More Tools -> Developer Tools) and checking for errors in the Developer Console.
Try running a server locally, hosting an html page and image, and pointing the image to the URL that this server is also hosting. Here is one way to do it:
Install node
Node.js quick file server (static files over HTTP)
Within that folder set up the following folder structure:
directory
index.html
image.jpg
Create index.html to have the code you want and point at "./image.jpg" with your w3 code like so:
<a href="./image.jpg" download>
<img src="./image.jpg" alt="W3Schools" width="104" height="142">
</a>
Hit your locally running server and try again: http://localhost/index.html

Opening other reports from a report (Working in webplayer)

Is there a way to open other dashboards/Reports ( saved in same server) from a report in web player.
I tried some python scripts which is used to access webpages but none of them is working in webplayer. My client want this to happen using buttons. So i prefer python scripts than HTML.
Much appreciated
Download an image of the button you want to use, like this one.
Add this image to a text area. Edit Text Area > Insert Image > (Select the downloaded image). Now you will see your "Button" image.
Edit the HTML and use href to the web page you care about. Notice the src= will already have your image name.
<a href="http://finance.yahoo.com/quotes/TIBX,Spotfire,S,Products?ltr=1&bypass=true">
<img src="ff08c65b55ab4b36acd5dacc78f03eea.png" border="0">
</a>

Form not submitted on click using watir-webdriver in Chrome

I am using ruby/cucumber/watir-webdriver and the page-objects gem to run my tests. My tests are usually run in firefox but decided to give chrome a try. While the click works in firefox it does not in chrome. Here is the sample html code:
<form id='test-form' method='post' class='validate-inline'>
...
<div class='margin-top'>
<input class='btn' data-disable-with='wait...' type='submit' value='Submit Form'></input>
</div>
</form
In my class page I have the button declared as the following:
button(:submit_form_btn, :value => 'Submit Form')
And call it this way:
submit_form_btn_element.when_present.click
I do see the button text change to 'wait...' for a few seconds then returns to 'Submit Form' but does not seem to submit the form. As mentioned before it works with firefox and when clicked manually. Just seems to be an issue in Chrome. Any ideas how to get around it?
I tried clicking the div, and tried clicking the button twice but same issue.
As always your help is appreciated. Thanks.
I know this question is little old now, but I thought I'd post in case this helps anyone.
Most of the times I've run into similar issues, it was caused by an update to Chrome that caused issues with the version of the watir-webdriver gem (or one of it's dependencies) or with the version of chromedriver that I was using. I've had success in the past by updating my gems and chromedriver and the other times I've had to roll back the browser version to the previous release.
It's not ideal to be testing on an older version of chrome but it worked fine as a stop gap until the issue was fixed.
If you do go for the previous version of chrome approach, make sure to log a bug ticket if there isn't already one there.

File Upload - Customise Browse window

I've got a bit tricky problem... I've got this file upload control which is only used for uploading profile images. When it is clicked it opens a Windows explorer Browse window. I would like this window to have the filter preselected on image files (.jpg, .png, etc.) and mine only has "All Files". This is what I'm talkin about:
I would also like to set a default location for the folder. Is there any way to set this Browse window?
You could achieve that if your browser supports HTML5 by adding the accept tag to your file input:
<input type="file" name="file" accept="image/jpg, image/gif" />
If your browser doesn't support HTML5 you are pretty much busted. Prefiltering file input dialogs in legacy browsers to a certain file type simply is not supported. You will have to use Flash or some equivalent client side scripting technology. You might take a look at some file upload controls such as Plupload, BlueImp and Uploadify which are abstracting much of this hassle for you.

ie8 window.open xls does not work

I have a simple html page to open a different HTML based on a OPTION list using an ON CHANGE to fire the WINDOW.OPEN,
In IE8, I get a window appear and disappear real fast when I select May10.
when I select SFAA or google, it works fine and opening the xls file using A HREF works fine too.
I try this in Firefox(3.6.13), chrome and everything works fine.
`<select name="target"
onChange="if (this.options[this.selectedIndex].value != '')
{window.open(this.options[this.selectedIndex].value,'_blank');};" >
<option VALUE="" style="color:#000000;">Select</option>
<option VALUE="http://www.google.com">google</option>
<option VALUE="../May10.xls">May 10</option>
<option value="../sfaa.pdf">SFAA</option>
</select>`
window.open(this.options[this.selectedIndex].value,'_blank'); does not work in IE8. '_parent' or '_self' works in IE8 too.
everything works fine in Firefox and google chrome
I came across a solution on web, replace js call
window.open(this.options[this.selectedIndex].value,'_blank');
with
var w = window.open(this.options[this.selectedIndex].value,'_blank');w.location.href = this.options[this.selectedIndex].value;
It woks fine in both IE8 and firefox.
Can you maybe post a screenshot or description of the window or info message that appears?
...cause it works fine for me when I tried on IE8/Windows 7/MBP.
What I did is I made an html file of your code you posted and when I selected my own xls file (saved in Excel 2007) in IE8, it prompted me with the dialog to open/save/cancel the file (like when you download an attachment) and I can select to view it, and the document opens up successfully.
Maybe also check the relative path you've supplied whether it is right that the named file exists and is not corrupted and your computer is programmed to run xls files with Excel by default?
What headers do you see on the HTTP response for the XLS file (e.g. look in Fiddler)?
If it cannot be downloaded (e.g. due to no-cache headers) then you might see bad behavior like this.
http://blogs.msdn.com/b/ieinternals/archive/2009/10/03/internet-explorer-cannot-download-over-https-when-no-cache.aspx

Resources