-
May 20th, 2007, 04:46 PM
#1
webbrowser
I'm trying to make a little app that will use the webbrowser to go to megaupload.com and upload a file
but I'm having trouble filling out the form that has the file you upload, I think it's called uploadform.file.
I can fill out other forms ok, for example the recipient's email form, I use WebBrowser1.Document.uploadform.toemail.Value = "email@email.com"
but this same code isn't working for the file form
-
May 21st, 2007, 09:51 AM
#2
Re: webbrowser
It works for me. Are you sure you are attempting to change it after the document has already completed loading?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 22nd, 2007, 06:13 PM
#3
Re: webbrowser
yes I think so.. I can show you my code
Private Sub Form_Load()
WebBrowser1.Navigate "http://megaupload.com"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WebBrowser1.Object) Then
WebBrowser1.Document.uploadform.file.Value = "C:\test.txt"
End If
End Sub
-
May 23rd, 2007, 07:43 AM
#4
Re: webbrowser
Well, in this scenario, you can't use WebBrowser1_DocumentComplete because that doesn't wait for embedded or onload objects. Megaupload.com is based on flash. That is an embedded object and therefore might not be loaded. To test my theory, I used the DocumentComplete and a standard button to call the changing of the text input. The DocumentComplete did not work, while I waited to see everything and the button did.
Take a look here to see some solutions to this problem.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 23rd, 2007, 04:18 PM
#5
Re: webbrowser
I still can't fill out the form when the page is completely loaded, I waited for everything to load then used a button
Private Sub Command1_Click()
WebBrowser1.Document.uploadform.file.Value = "C:\test.txt"
End Sub
Can I see what code you used to fill out that form?
-
May 23rd, 2007, 04:50 PM
#6
Re: webbrowser
If you're trying to set the Value property of an HTMLInputElement with the TYPE attribute of FILE, you won't succeed.
(e.g. the HTML tag looks similar to: <INPUT TYPE=FILE NAME="uploadfile"> )
The HTMLInputElement's Value property is read only. It can only be assigned by the user bringing up the file selection dialog. From what I've heard, it's a security means to prevent people from creating hidden file upload objects on their forms for discreetly uploading files from your computer.
Last edited by ChaosTheEternal; May 23rd, 2007 at 04:52 PM.
-
May 24th, 2007, 05:34 PM
#7
Re: webbrowser
Thanks, at least now I know what's wrong. So there isn't any workarounds for this problem? If not I guess winsock would be the only way to upload a file then right?
-
May 24th, 2007, 05:52 PM
#8
Re: webbrowser
Or create a batch file that will FTP it up.
-
May 24th, 2007, 11:06 PM
#9
Re: webbrowser
You could use click() to activate the open dialog window and then send keystrokes to specify the file's path.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 25th, 2007, 09:23 AM
#10
Re: webbrowser
Originally Posted by PeejAvery
You could use click() to activate the open dialog window and then send keystrokes to specify the file's path.
Unfortunately, you can't. Using either the WebBrowser control or an IE object, if you programmatically click the "Browse" button, your program is blocked, waiting for the dialog to be dismissed.
If you launch the Browse dialog from IE itself, it won't block your application and you could send the message to the browse dialog, but for full automation, you couldn't bring up the dialog and specify a file with one single-threaded VB application.
EDIT: And I am wrong. It can be done.
Last edited by ChaosTheEternal; May 25th, 2007 at 02:50 PM.
-
May 25th, 2007, 11:04 AM
#11
Re: webbrowser
Originally Posted by ChaosTheEternal
Unfortunately, you can't. Using either the WebBrowser control or an IE object, if you programmatically click the "Browse" button, your program is blocked, waiting for the dialog to be dismissed.
I have done it before in older versions of Visual Basic. Hmmm. Maybe there was a trick to doing it. When I get to work, so I can use a PC (I'm a Mac user), I will open one of my older programs to see.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 25th, 2007, 01:23 PM
#12
Re: webbrowser
Originally Posted by PeejAvery
When I get to work, so I can use a PC (I'm a Mac user), I will open one of my older programs to see.
Update: WebBrowser1.Document.uploadform.file.Click works perfectly fine in older versions and in VB6.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 25th, 2007, 01:33 PM
#13
Re: webbrowser
Originally Posted by PeejAvery
Update: WebBrowser1.Document.uploadform.file.Click works perfectly fine in older versions and in VB6.
In VB6, with a Reference to Microsoft Internet Controls (using IE7) and the following code:
Code:
Option Explicit
Private WithEvents ie As InternetExplorer
Private Sub Form_Load()
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_FILE.html"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set ie = Nothing
End Sub
Private Sub ie_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If ie.ReadyState = READYSTATE_COMPLETE Then
ie.Document.Forms.Item(1).Children.Item(0).Click
MsgBox "Tinker with it"
End If
End Sub
The message box doesn't show up until the file browser dialog is dismissed.
I can't test IE6, but I wouldn't expect it to react differently.
-
May 25th, 2007, 02:24 PM
#14
Re: webbrowser
So use a timer...
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
WebBrowser1.Visible = True
WebBrowser1.Navigate "http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_FILE.html"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If WebBrowser1.ReadyState = READYSTATE_COMPLETE Then
WebBrowser1.Document.Forms.Item(1).Children.Item(0).Click
End If
End Sub
Private Sub Timer1_Timer()
opendialog = FindWindow(vbNullString, "Choose file")
If opendialog > 0 Then
SendKeys "Tinker with it"
Timer1.Enabled = False
End If
End Sub
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 25th, 2007, 02:52 PM
#15
Re: webbrowser
For some reason, I believed the Timer control in VB6 was tied to the UI thread and wouldn't trigger if it were blocked.
I guess I'm wrong. And I'm glad to be proven wrong rather than falsely believe I was right.
EDIT: Doesn't seem to work with an IE object, though. Works fine with a WebBrowser control.
Last edited by ChaosTheEternal; May 25th, 2007 at 02:59 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|