Delphi: click web page buttons by code to initiate download - javascript

I am new to web development so please be patient.
I need to automate downloading a CSV file from an online location service every half hour. I am using Delphi 11.2 and WebView4Delphi. I can navigate to the page, but cannot figure out how to click the button and wait for the response before clicking the next.
I have tried:
WVBrowser.ExecuteScript('document.getElementById("linkRefresh")[0].click()');
...and different variations.
I need to click two buttons:
<a id="linkRefresh"
href="#"
class="tools refresh report-action"
data-action="refreshReport"
data-event="click">
...and:
<a id="linkCSV"
href="#"
class="csv report-action tools"
data-action="exportCsv"
data-event="click">
Then the "Save As" button, give a filename, and finally "Yes" to overwrite the existing file.

Related

iOs download pictures in photos instead of files

I have a website that provides images and I give users the possibility to download them.
There is an issue with the iOs users, the photos that are downloaded thanks to the button I made, go directly to the "Downloads" folder of the iPhone. (See #1)
The only way for the photos to go to the right folder is to make a long click on the photo and click on "Add to Photos". (See #2)
I would like these photos to be downloaded to the photo folder by clicking on the button.
Is there a solution?
#1 / <a href="photo.jpg" download> Download </a>
#2 /
Thank you

Selenium - button click downloads but doesn't redirect to linked page

I'm trying to click a "Download" button in a pop-up on a webpage. When I click it using Selenium (Chrome; Python), I know it's working because the file gets downloaded.
However, in addition to the javascript that downloads the file, the button has an href=# which should re-direct to the underlying page, (without the pop-up) once it's been clicked. When I click it in a live session using my mouse, the behavior is correct. But when using [button].click() in Selenium, the redirection is not happening - only the file download. Any tips or suggestions?
Edit: code snippets
Here is the button html:
<div class="buttons popup__buttons">
<a href="#" class="button js-downloadLink">
Download
</a>
</div>
And my selenium code:
driver.find_element_by_class_name('button.js-downloadLink').click()
My suggest is to open chrome dev-tools and investigate what action is triggered by javascript. You may need to run a function with selenium that for some reason is not calling when using Selenium or check if the ids are loading properly.
if you want help share the website you want to scrape and we can have a look.
Every website is a new world! Hope it helps.
EDIT:
Still no idea with your snippet. Try the devtool. More precisely to the event listeners where its says click():

Open Chrome PDF viewer dialogue with JavaScript

I am trying to offer users the option to save the current webpage as a PDF using Chrome natively, no other browser support is required and introducing a 3rd party system is not a practical option.
Currently I have to manually instruct the user where the "Open PDF in Preview" link is within the print dialogue and only offer the following button:
<a href="#" onclick="event.preventDefault(); window.print();">
PDF Preview
</a>
I would like to jump the user straight to the PDF preview dialogue for them to save, the following will of course not work, but is more similar to what I would like to achieve.
<a href="#" onclick="event.preventDefault(); window.print('pdf');">
PDF Preview
</a>
It is not possible to do this.
Chrome currently meets the HTML standard as "print" generically means obtaining the page in some physical way, be that a traditional printed document or a PDF. How it chooses to do this is up to the browser vendor.
Additionally Chrome users can select their default action for printing to be PDF or a printer on their network.
From that I would infer that it's unlikely Chrome would let the web application override the user preference.
Sources
https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#simple-dialogs
https://html.spec.whatwg.org/multipage/rendering.html#obtain-a-physical-form
https://productforums.google.com/forum/#!topic/chrome/D0CYzpWx7xE;context-place=topicsearchin/chrome/save%20as%20PDF

Single page architecture or application in web site in html navigation using servlet without opening a new page

Actually I want to download the files using a servlet on click of link.
I am using single page architecture or application in web site in HTML.
How to call servlet on clicking of a link without change in page?
I am trying but next page is opening so can I restrict the opening a new page on link? I want to make a dynamic web page. I want to load the image on click of the link.
Here is some code:
<form action="./dwfile" method="get or post">
<a class="btn_loadmore btn btn-lg btn-orange" href="dwfile?#templatemo-archives" role="button">DOWNLOAD MORE SCREENSHOTS</a>
</form>
When the users click on DOWNLOAD MORE SCREENSHOT link then they remain on the same page and the dwfile servlet should be invoked, i.e folder will be downloaded. And they will navigate to the next template i.e. #templatemo-XXXX
You are using form tag so every time your form is submitted.
when the user click on DOWNLOAD MORE SCREENSHOT link then it remains
on a same page and the dwfile servlet should be invoked.
Then there is no need of form tag here. Only a link needed to download your file. Just use
DOWNLOAD MORE SCREENSHOT
Use the target attribute to determite how the href should be executed.
More informations:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target
For e.g.:
<a class="btn_loadmore btn btn-lg btn-orange" href="dwfile?#templatemo-archives" target="_blank" role="button">DOWNLOAD MORE SCREENSHOTS</a>
If you want to really make it dynanimc you should think about using httpRequests.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

Opening PowerPoint after clicking a html link

I have a link in my webpage. When someone clicks the link I want to start the PowerPoint application in the user's desktop with an image in the slide. There are too many of such links and so I can not create separate ppt files for each links.
I can do the following with excel.
<a href="http://localhost/excel/asheet.xls#Sheet2!D4">
This link will open the Excel file to the second page with the focus on cell D4
</a>
So is it possible to do something for PowerPoint like this
<a href="http://localhost/template.ppt#image1.jpg">
This link will open PowerPoint with image1.jpg in the slide.
</a>
Or any JavaScript hack will also help.

Categories