In short:
How do you 1. Focus on a prompt popup on IE, 2. Type in a value, and 3. Return?
In Long:
Hi,
I am trying to automate a login/file-downloading process on a company intranet server through VBA. I have gotten the log-in and navigating working, however am stuck on trying to download a file from the site.
The ‘Download’ works as follows:
- When the ‘Download’ button is clicked, ‘createFileForDownload’ is triggered
- Then the user is prompted to input a string
- If there is no input, or if you click “cancel” on the popup it alerts an error message
- If there is a valid input, it begins to compile a file and downloads it to the PC
CODE :
function createFileForDownload(){
// Main function triggered when the 'Download' button is clicked
var reason = getReasonForDownload();
if (reason){
//Retrieve data from server and create the file for downloading
}
}
function getReasonForDownload(inputName){
// The function I cannot get past
var reasonForDownload = prompt("Specify the reason for your download", "");
if (reasonForDownload && reasonForDownload .length > 0) {
return "<input type='hidden' name='" + inputName + "' value='" + reasonForDownload +"'>";
} else {
alert("You must input a value");
closeHiddenWaitingFrame();
$('.waitingPop').removeClass("open"); //Close the waiting frame
return false;
}
}
PROBLEM:
However, when I try to access the prompt, it pauses the running VBA code.
Is there any way I could input a string to the prompt and ‘enter’?
What I have attempted so far:
SendKeys
- only runs after the prompt is shown, and I am unable to change focus to the prompt without clicking it manually
Overwriting the OnClick method
- I cannot override the enter onclick function, because the function itself contains the code to actually construct the file for downloading.
- I was hoping there would be a way to overwrite the ‘getReasonForDownload’ function and return it, however it seems I would have to rewrite the entire ‘createFileForDownload’ function to achieve what I want.
Sorry about the lack of info; I cannot post the actual site or code online due to the company’s privacy issues.
Any help would be greatly appreciated: thank you so much in advance!
halp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1