plastix Posted March 23, 2006 Share Posted March 23, 2006 hi all. Am using Dale Hohms' IE UDFs to monitor IE session. Have been experimenting with various functions of beta / UDFs. Some users have been using a webmail system (which i cannot modify) to send confidential information (accidentally) - i am hoping to write a resident process that will monitor attachements and warn user prior to sending etc. I am using the _IEAttach() method to attach to an IE object, and monitor for the relevant form field details. If the File borwser field is populated, the script reads in the file path and extracts the file extension (which is unique for the 'safe' files): $o_Form = _IEFormGetObjByName ($oIE, "Form") $o_attach = _IEFormElementGetObjByName ($o_Form, "attach") $attachfile = _IEFormElementGetValue($o_attach) $file_ext = StringSplit($attachfile,".") If $file_ext[0]= 1 Then msgbox(0,"Oops","Selected file doesn't seem to have an extension at all...") If $file_ext[0] > 1 And NOT ($file_ext[$file_ext[0]] = "safe") Then _IEFormElementSetValue($o_attach," ") $o_attach.focus() ControlFocus("","",$o_attach) ControlClick("","",$o_attach) ... As you can see, the code tries to blank the value of the file field (which doesn't work), and as a second attempt try to press the "browse" button again to prompt for attaching an alternate file - which also doesn't work... but as you can see i am not specifying window title details (but even doing so fails without error). One option, i guess, is to read all the other form fields into an array, then use _IEFormReset(), replacing all the other fields with _IEFormElementSetValue() - which i guess will work - but wonder if there is a means of ideally clearing this field directly, and / or re-opening the file browser/picker button ? QUESTIONS (Sorry there are many - learning ++ TIA): 1. How to directly clear file browser / form field and click browse button (example above). 2. Actually, I had tried another method initially - which is worth asking about for knowledges' sake... I used WinGetHandle() to ease monitoring / control of IE - but notice that you can't use the $handle pointer in ControlGetHandle() or ControlCommand() - i still have to specific the window title / text details - is there an equivalent command system that i can use using the $handle ?? 3. I tried manipulating the file browser window combobox by adding the file extension string using... $filepicker = WinGetHandle("classname=#32770") ControlCommand("Choose file","Look &in:","ComboBox3","AddString",'Encoded Files (*.safe)') I can add/delete the entries OK... but if i try to focus on the new entry IE crashes - again, as you can see despite finding the handle of the file picker window, have to still specify title etc to attach / manipulate combobox... but trying to set new value crashes... thus i abandoned approach for method above - unless anyone has a workaround / correct code. TIA 4. i know there was a 4th.... but can't think right now One option, while i am writing this, might be to hijack the native HTML / form code and insert javascript using _IEBodyWriteHTML() to actually add javascript validation system to page... might look into that next if the above is a problem. Again - any help greatly appreciated. Loving this stuff Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted March 23, 2006 Moderators Share Posted March 23, 2006 1. How to directly clear file browser / form field and click browse button (example above).Can you manually edit this form, or do you have to click the browse button to change the value?Also could you post the source for the form? Link to comment Share on other sites More sharing options...
plastix Posted March 23, 2006 Author Share Posted March 23, 2006 @big_daddy - thanks. yes - you can manually edit the field in the browser without pressing the browse button.Simplified page source:<HTML><HEAD><TITLE>Webmail - Company</TITLE></HEAD><B>COMPOSE MESSAGE</B><form method="post" action="/mail.pl" enctype="multipart/form-data" name="composeform"><input type="hidden" name="action" value="sendmessage" /><input type="hidden" name="sessionid" value="randomsessionidnumber" /><input type="hidden" name="composetype" value="continue" /><input type="hidden" name="sort" value="date" /><input type="hidden" name="firstmessage" value="1" /><input type="hidden" name="folder" value="INBOX" /><B>From:</B>Me@Home.net<br /><B>To: </B><input type="text" name="to" size="70" /><br /><B>Reply To: </B><input type="text" name="replyto" value="guest@home.net" size="70" /><br /><B>Attachment: </B><input type="file" name="attachment" tabindex="-1" size="60" /><input type="submit" tabindex="-1" name="Add" value="Add" /><br /><B>Subject: </B><input type="text" name="subject" size="70" /><br /><textarea name="body" rows="15" cols="72" wrap="hard"></textarea><br /><input type="submit" name="Send" value="Send" /></form> <!-- End of message composition form --><form method="post" action="/mail.pl" enctype="multipart/form-data"><input type="hidden" name="action" value="displayheaders" /><input type="hidden" name="firstmessage" value="1" /><input type="hidden" name="sort" value="date" /><input type="hidden" name="folder" value="INBOX" /><input type="hidden" name="sessionid" value="randomsessionidnumber" /><input type="submit" name="Cancel" value="Cancel" /></form></BODY></HTML>TIA Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted March 23, 2006 Moderators Share Posted March 23, 2006 Well so far I've gotten this far: #include <IE.au3> $oIE = _IEAttach("Webmail") $o_Form = _IEFormGetObjByName ($oIE, "composeform") $o_attach = _IEFormElementGetObjByName ($o_Form, "attachment") $attachfile = _IEFormElementGetValue($o_attach) _IEFormBrowse($o_attach) Func _IEFormBrowse($o_object) ; $o_object - IE form object ; return 1 always If IsObj($o_object) Then SetError(0) $o_object.Click () Return 1 Else SetError(1) Return 0 EndIf EndFunc ;==>_IEFormBrowse Link to comment Share on other sites More sharing options...
DaleHohm Posted March 24, 2006 Share Posted March 24, 2006 (edited) the browser will not allow script control of a file input box- its a security thing. Dale Edited March 24, 2006 by DaleHohm Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted March 24, 2006 Moderators Share Posted March 24, 2006 the browser will not allow script control of a file input box- its a security thing.DaleTrue, but the funtion I made does click the button. However it also pauses the script until you either select a file or click the cancel button. Is there a way around this, other than calling a different script? Link to comment Share on other sites More sharing options...
plastix Posted March 24, 2006 Author Share Posted March 24, 2006 @big_daddy - many thanks for your efforts. will try this function out on live site... clicking the button is very helpful. @DaleHolm - many many thanks for the IE UDF. I assumed it was a security thing... shame. do you think injecting the HTML with a javascript field validation code on detecting the form would work ?? will tinker further today and report back. thanks again Link to comment Share on other sites More sharing options...
DaleHohm Posted March 24, 2006 Share Posted March 24, 2006 @big_daddy - many thanks for your efforts. will try this function out on live site... clicking the button is very helpful.@DaleHolm - many many thanks for the IE UDF. I assumed it was a security thing... shame. do you think injecting the HTML with a javascript field validation code on detecting the form would work ??will tinker further today and report back. thanks againThere is an example in reply 3 of the IE.au3 thread of using SEND to manipulate the file input element. Injecting HTML won't work either because the default value for the field is also now ignored by the browser for the same security reasons. Using .focus and the AutoIt SEND commands (as in the example) are the best suggestions I know of.Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
plastix Posted March 25, 2006 Author Share Posted March 25, 2006 just to wrap up this thread for anyone else with a similar problem, both methods work well.infact, i have combined the two... to clear the form field and press the file browse button:$o_object.focus Send("^a") $o_object.focus Send("{BS}") $o_object.focus $o_object.Click ()The regular 'focus' command is probably not required, but i originally had a messagebox popup that shifted focus / users may click on page etc etc - so ensures that focus is in right place prior to action.Thanks again to DaleHolm & big_daddy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now