IE automation send the HTTP Post directly to the form action using VBA - vba

I am having some automation trouble.
I am using HTML Object Library to automate an download. At the end of the automation process, I have to click a submit button of a form and then the download starts.
When I try to handle the dialog with the winapi32 function like this:
hWndDialog = 0
'Wait until the dialog is open
While hWndDialog = 0
hWndDialog = FindWindow(vbNullString, "Dateidownload")
Wend
'get the handle of the button
hWndDialogSpeichern = FindWindowEx(hWndDialog, 0, "Button", "&Speichern")
Call SetForegroundWindow(hWndDialog)
'send message
lRetval = SendMessage(hWndDialogSpeichern, &H5, ByVal 0&, ByVal 0&)
Nothing happens. I read something, that this isn't possible, because the dialog is modal?
So I try to send the POST data directly to the form's action. I think this is the best possibility even.
But I don't know what to send to the server.
Here the form in the html page:
<form action="/smarti/bismt/bismt/resexport" method="post">
<input class="active" type="button" onclick="submitform()" name="button_export" value="Export">
submitform() only check some values and then calls:
document.forms[0].submit();
However, when I send a POST request to "/smarti/bismt/bismt/resexport" I only get the page. I don't know how to set up the request header. Tried to use firebug, to see what is sending to the form, but saw nothing I recognized.

Did you try adding a question mark ? and then the names of the text input boxes? Like http://zip4.usps.com/zip4/zcl_3_results.jsp?zip5=92101.

Related

Click String That Runs Javascript

I am trying to click a string of text within a web browser control that runs some javascript, I am unsure how to click the text as the method I use for buttons does not work in this instance
Function Clk(WebBrowserID, ElementID)
WebBrowserID.Document.GetElementById(ElementID).InvokeMember("click")
Return "Clicked"
End Function
This is all that is visible to the client in regards to the clickable text
<div class="task-skip pure-g">
<div class="pure-u-1">
Next
</div>
</div>
I am completely lost on how to either click the text so that the javascript script runs or to invoke the script through code so the button does not need to be pressed, any help would be greatly appreciated.
The solution that I found and worked is as below hope this will help anyone else with the issue.
For Each Element As HtmlElement In Browser.Document.All
If Element.InnerText = "TEXT HERE" Then
Element.InvokeMember("click")
End If
Next
Return "RETURN VALUE"

“Click” a javascript button with VBA

I am trying to use VBA to click the button: search job posting
button
The html code:
<td><br> <input type="submit" class="btn btn-primary btn-small" value="Search"></td>
<td><br>-or - Search Job Postings
I was attempting to do it by something like:
IE.document.Something.Click
Much appreciation for someone who can help me to figure out the "something"!!!
There are probably better ways to identify a button, but when I was testing this stuff for fun a long time ago checking the onclick property was the only reliable way to identify a button on the site I was interfacing with. I'm assuming you know how to reference the browser window based off what you said. I included the Microsoft HTML Object Library to get the HTMLButtonElement type.
Dim htmlElements as Variant
Dim buttonElem As HTMLButtonElement
Set htmlElements = IE.Document.getElementsByTagName("BUTTON")
For Each buttonElem In htmlElements
If InStr(1, buttonElem.onclick, "orbisApp.buildForm({action:'displayAdvancedSearch'}).submit()") > 0 Then
buttonElem.Click
End If
Next
All you need to do is simply use the form element to click the button. Your statement:
IE.document.Something.Click
Is almost spot on.
Here's the code you want to use
IE.document.Forms(0).Submit

WQO agent and LotusScript

I am trying to create a div tag in WQO agent using Lotusscript as below :
In my form it is blank form
Dim session As New NotesSession
Set thisdb = session.CurrentDatabase
Set doccontext = session.DocumentContext
Print | </form> _
<form name ="thisform" _
<form name ="thisform" > _
<div id ="thisform"> _
Please wait while we proces your request ........<img src='./please-wait.gif' width=50 height=50></img> _
</div> _
</form> |
However this outputs nothing, am I doing anythign wrong here ?
Edit :
Basically I wanted to print view html view with button to delete the selected records, but before I want to make sure that please wait is being displayed before it prints HTML view.
As per the help page for WebQueryOpen and WebQuerySave agents, you can't use a print statement in a WQO agent to send HTML to a browser.
A WebQueryOpen event runs the agent before Domino® converts a document
to HTML and sends it to the browser. Domino ignores any output
produced by the agent in this context.
You need to put a field in the appropriate place on the form, mark it as pass-through HTML, and have your WQO agent save the HTML into the item value for that field.

Using VBA, how do I input a value to a <input> text box on a webpage that uses Knockout JS?

I'm trying to populate a form on a webpage that uses Knockout JS. When I insert a value into a particular text box it appears to have taken the value but when I submit the form it retains it's previous value. With a bit of digging around I've discovered that Knockout JS uses data-binding to update the underlying value. When I insert a value into the input text box the Knockout JS is not being triggered and therefore not updating the underlying value. This post is for something similar but with a check box and dropdown box rather than a text box. But I can't figure out how to get it working with a text box.
The actual website I'm trying update requires a login, however I think this page on the Knockout JS Site http://knockoutjs.com/examples/helloWorld.html will suffice for testing purposes.
Basically what I need is, using VBA, to enter a FirstName and LastName in the 2 text boxes (where it currently says 'Planet' and 'Earth'). You should see the 2 input values appear immediately below where it says 'Hello Planet Earth'. Typing it manually into the text boxes works fine. But I just can't get it to work in VBA.
Here' what I have so far...
Sub KnockoutTest()
Dim IE As New InternetExplorer
Dim hDoc As HTMLDocument
IE.Visible = True
'Load webpage and loop until loading is complete.
IE.Navigate "http://knockoutjs.com/examples/helloWorld.html"
Do While (IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE)
DoEvents
Loop
Set hDoc = IE.Document
Set firstName = hDoc.getElementsByClassName("liveExample").Item(0).all.Item(1)
Set lastName = hDoc.getElementsByClassName("liveExample").Item(0).all.Item(3)
firstName.Click
firstName.Value = "Joe"
lastName.Click
lastName.Value = "Bloggs"
'Close ie object
Set IE = Nothing
Application.ScreenUpdating = True
End Sub
Anyone got any ideas on how I get the knockout events to fire?
The actual html from the text box on the page I'm trying to update is this....
<input type="text" ondrop="return false;" onpaste="return false;" data-bind="numericValue: Markup, visible: IsCellEditable(), selected: IsCellEditable(), event: { blur: blurZoneMarkup, keypress: function (data, event) { return $parent.isDecimal(data, event, hdnIsDiscount) }, keydown: function (data, event) { $(event.target).data('tabcode', event.which || event.keyCode); { return true; } } }" style="width: 90%; display: none;">
Any help or advice would be much appreciated. I've been trying to solve this for 3 days now!
Basically, you would need to handle such automated inputs as 'HTMLevents' and trigger them. An updated snippet from your original code:
With hDoc
Set evt = hDoc.createEvent("HTMLEvents")
evt.initEvent "change", True, False
firstName.Value = "Joe"
firstName.dispatchEvent evt
End With
Tested this code and works fine for the website that link that you have provided.
I have done tons of website automations with VBA and the most robust approach is to create one event, specific to each field that you would want to fill, assign a value to the field, and dispatch the event that you have created.
For further information, refer to the documentation on MSDN https://msdn.microsoft.com/en-us/ie/ff975247(v=vs.94)

IFRAME with HTA prompt with VB

I have an HTA prompt with VB code. I would like a URL loaded within the HTA window when the "SUBMIT" button is clicked. However, I cannot find any information that is helpful for my situation. Can someone please help me include an iframe in my HTA prompt so that a website can be displayed? I can use https://www.google.com as an example. Let me know if you have any questions.
Here is the code I currently have for the submit button:
bodystring = bodystring & "<BR><BR><BUTTON CLASS='Bttn_Back' OnClick='PrevStage()'>BACK</BUTTON> <BUTTON CLASS='Bttn_Submit' OnClick='NextStage()'>SUBMIT SURVEY</BUTTON>"
Here is my section of code for the "NextStage()" function:
ElseIf STAGE = 62 Then
SaveResults()
Window.Close()
End If
Put this to the HTML of the HTA:
<iframe id="htmlhere" src="" style="display: none;"></iframe>
Then in nextStage():
document.getElementById("htmlhere").src = "http:/..."; // Loads a new document to iframe
document.getElementById("htmlhere").style.display = ""; // Setting style.display empty shows the iframe
Sorry for using JS, but my VB skills are more or less zero.