I am trying to auto-populate a webserver html page using VB6 and the webbrowser control.
I can go to the URL, get it to auto log-in, and then change the URL to one of the site's webpages.....but I cannot populate a
input type="file" field using the ".value" statementbecause (I understand) this is seen as a basic security risk by Microsoft and not allowed.
So, I am wondering if I can use Sendkeys or another method in VB6 to fill in the field, and if so, how do I identify the field, focus to it, and then use Sendkeys to populate it on the web page?
The problem is that the web page uses a "Browse" button to open a file dialog box so you can find and select the file you want, but I already know the name I want to select, and then there is a "Send" button once the file is selected. I can activate the Send button event no problem, but with no file name entered in the firmware file name field, I get an error returned.
The SECOND problem I have is that once you send the Send button event, a Java Alert box opens which has an "OK" button on it, which I havent figured out (yet) how to programmatically emulate and create a click event for in VB6.
I have browsed the web and experimented for a few nights to get further but have thus far not got any further in this quest. Any help or directions to a tutorial or example would be greatly appreciated.........
My (simple) VB6 code thus far;
Code:
Dim starttimer, delaytime
Dim url
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, url As Variant)
If url = "http://123.123.123.123/" Then
WebBrowser1.Document.All("username").Value = "admin"
WebBrowser1.Document.All("password").Value = "admin"
WebBrowser1.Document.All("button").Click
delaytime = 5 ' wait for login to be completed
Call TimerLoop1
WebBrowser1.Navigate "http://123.123.123.123/html/cfg_update.html"
Exit Sub
ElseIf url = "http://123.123.123.123/html/cfg_update.html" Then
' need to identify "filename entry" field on cfg_update.html webpage and setfocus on it
' how ????
SendKeys "C:/Updater/NewConfig.dat", True ' send filename to filename entry field
WebBrowser1.Document.All("submit").Click ' click the "Send" button on the page
Exit Sub
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
DLstart = False
WebBrowser1.Navigate "http://123.123.123.123"
End Sub
Private Sub TimerLoop1()
Timer1.Enabled = True
starttimer1 = Timer
Do While Timer < starttimer1 + delaytime
DoEvents
Loop
Timer1.Enabled = False
End Sub
the relevant website source code is;
Code:
<input type="file" name="firmware" />
</p>
<p align="right">
<input name="submit" type="submit" value="Send" onClick="alert('NOTE - This may take several minutes.\r\nPlease wait.');progress.style.display = 'inline';">
</p>
</form>
<span id="progress" style="display:none">
<p align="center"><img src="images/ajax-loader.gif"></p>
</span>
<!-- InstanceEndEditable -->