|
-
Apr 3rd, 2011, 01:17 PM
#1
Thread Starter
New Member
Dynamically setting the value for a file input box in a WebBrowser page?
I'm creating a program that ought to automatically populate a form on a web site with information, and then submit that form. I've done this kind of thing a lot before, but this time I'm running into an interesting problem -- the "input type=file" element.
With the "input type=file" element, a filename box is automatically created along with a Browse button. Clicking the filename box opens the file browser -- you can't type in the filename box manually.
For my program, however, I want to manually set the value of this filename box. Usually, I would just get the element from the page, then call: element.SetAttribute("value",myNewValue). However, with the "input type=file" element, that hasn't worked, presumably because the user cannot normally manually edit the value of the box (though I could be wrong about that being why).
I've tried one alternative: calling element.InvokeMember("setAttribute(''value',''" + myNewValue + "'')"). The MSDN documentation of the "input type=file" object suggested this might work, but I didn't get a result. (Source, for reference: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx )
Any suggestions for how to accomplish this? Either a way to bypass the prevention of manually modifying the filename box, or a way to dynamically put my desired file into the file browser box that pops up?
I've asked this elsewhere once, and one reply was about how I shouldn't be attempting to write a server that will accomplish this anyway -- so let me make sure it's perfectly clear, I'm just writing a client program that ought to mimic what I would be doing anyway. Its purpose is that there's a particular site that I submit things to whose interface only supports one submission at a time, and I have several hundred things I need to submit.
-
Apr 3rd, 2011, 02:37 PM
#2
Thread Starter
New Member
Re: Dynamically setting the value for a file input box in a WebBrowser page?
My further research has made it clear that preventing the user from manually setting the value of an input type=file element is specifically forbidden. So, I'm trying to find a different way to go about this.
My main attempt is to near-perfectly mimic what a user would actually do to upload a file. To do this, my latest attempt was to find the FILE element, invoke its 'Click' method (which brings up the file browser from the site), and use SendKeys to send the path I want to the program -- unfortunately, that hasn't worked because when the 'click' method is invoked, the program execution seems to stop until it receives the result from the file browsing window, which means I have no idea how to send the file browsing window any commands. Hmm.
My other idea was to manually change the type of that input box from 'file' to 'text', but when I do that, I inexplicably get a host of JavaScript errors -- presumably coming from the act of changing it, rather than from the change itself.
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
|