jones Posted July 15, 2010 Posted July 15, 2010 I am newbie on the forum. I have been referring to the forums to get any help on autoit. I have used _IEFormGetObjByName,_IEFormElementGetObjByName,_IEFormElementSetValue to input values in a form. In the particular situation presented below, I have selected the option using _IEFormElementOptionselect but could not setvalue to the "value" of the option.I have tried many functions such as _IEFrameGetCollection,_IEGetObjById,_IETagNameGetCollection but could not succeed in setting value to the option The source code is as follows: <option value='ESRB'>ESRB</option> <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" /> I would like to setvalue to the 'ESRB' option and would like to get help out here in solving the trouble I have been facing since two days. Thanks
PsaltyDS Posted July 15, 2010 Posted July 15, 2010 I don't think it's proper HTML to have that input tag inside the select/option tags, but this works anyway: #include <IE.au3> $sHtml = '<html>' & @CRLF & _ ' <body>' & @CRLF & _ ' <form action="">' & @CRLF & _ ' <select name="selections">' & @CRLF & _ ' <option value="ABCD">ABCD</option>' & @CRLF & _ ' <option value="EFGH">EFGH</option>' & @CRLF & _ ' <option value="IJKL" selected="selected">IJKL</option>' & @CRLF & _ ' <option value="MNOP">MNOP</option>' & @CRLF & _ ' <option value="ESRB">ESRB</option>' & @CRLF & _ ' <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" /> ' & @CRLF & _ ' </select>' & @CRLF & _ ' </form>' & @CRLF & _ ' </body>' & @CRLF & _ '</html>' $oIE = _IECreate() _IEDocWriteHTML($oIE, $sHtml) Sleep(2000) $oForm = _IEFormGetCollection($oIE, 0) ; Get first form by index $oSelect = _IEFormElementGetObjByName($oForm, "selections") _IEFormElementOptionselect($oSelect, "ESRB") Sleep(2000) $oInput = _IEFormElementGetObjByName($oForm, "metakeyinput") _IEFormElementSetValue($oInput, "ESRB Be Me!") But maybe I don't understand what you are trying to do. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
jones Posted July 15, 2010 Author Posted July 15, 2010 Let me present you the entire code for clarity<div id="postcustom" class="postbox " > <div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span>Custom Fields</span></h3> <div class="inside"> <div id="postcustomstuff"> <div id="ajax-response"></div> <table id="list-table" style="display: none;"> <thead> <tr> <th class="left">Name</th> <th>Value</th> </tr> </thead> <tbody id="the-list" class="list:meta"> <tr><td></td></tr> </tbody> </table><p><strong>Add New Custom Field:</strong></p> <table id="newmeta"> <thead> <tr> <th class="left"><label for="metakeyselect">Name</label></th> <th><label for="metavalue">Value</label></th> </tr> </thead> <tbody> <tr> <td id="newmetaleft" class="left"> <select id="metakeyselect" name="metakeyselect" tabindex="7"> <option value="#NONE#">— Select —</option> <option value='ESRB'>ESRB</option> <option value='Publisher'>Publisher</option> <option value='Release Date'>Release Date</option> <option value='Thumbnail'>Thumbnail</option></select> <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" /> <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;"> <span id="enternew">Enter new</span> <span id="cancelnew" class="hidden">Cancel</span></a> </td> <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td> </tr> <tr><td colspan="2" class="submit"> <input type="submit" id="addmetasub" name="addmeta" class="add:the-list:newmeta" tabindex="9" value="Add Custom Field" /> <input type="hidden" id="_ajax_nonce-add-meta" name="_ajax_nonce-add-meta" value="0e681fd27c" /></td></tr> </tbody> </table> </div> I would like to setvalue to the option field when the option 'ESRB' is selected.Thanks
PsaltyDS Posted July 15, 2010 Posted July 15, 2010 (edited) What "option field" do you want to change? Modified demo: #include <IE.au3> $sHtml = '<html>' & @CRLF & _ ' <body>' & @CRLF & _ ' <form action="">' & @CRLF & _ ' <select id="metakeyselect" name="metakeyselect" tabindex="7">' & @CRLF & _ ' <option value="#NONE#">— Select —</option>' & @CRLF & _ ' <option value="ESRB">ESRB</option>' & @CRLF & _ ' <option value="Publisher">Publisher</option>' & @CRLF & _ ' <option value="Release Date">Release Date</option>' & @CRLF & _ ' <option value="Thumbnail">Thumbnail</option>' & @CRLF & _ ' </select>' & @CRLF & _ ' <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" /> ' & @CRLF & _ ' </form>' & @CRLF & _ ' </body>' & @CRLF & _ '</html>' $oIE = _IECreate() _IEDocWriteHTML($oIE, $sHtml) $oForm = _IEFormGetCollection($oIE, 0) ; Get first form by index $oSelect = _IEFormElementGetObjByName($oForm, "metakeyselect") Do Sleep(100) $sValue = _IEFormElementGetValue($oSelect) Until $sValue = "ESRB" ConsoleWrite("$sValue = " & $sValue & @LF) $oInput = _IEFormElementGetObjByName($oForm, "metakeyinput") _IEFormElementSetValue($oInput, "ESRB Selected!") Edited July 15, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
jones Posted July 15, 2010 Author Posted July 15, 2010 Thanks for the quick reply. Sorry,I could not get the results from the code. I am attaching an image of the form. I intend to autosubmit the form by setting values to the fields of the form. From the image, you could see the "Add New custom Field:", there is a dropdown menu where there are four options namely: ESRB,Publisher,Release Date,Thumbnail. I need to select the option from the dropdownmenu and submit its value in the text box placed to the right of the dropdownmenu in header named "value". Thanks for you regard to newbies on the forum with quick replies. P.S :The source code of the form is provided in the previous post
PsaltyDS Posted July 15, 2010 Posted July 15, 2010 Well, you still didn't post all of the html, so we can't tell if there's a Form, Frame, or iFrame to deal with, but this is still the general idea: $oForm = _IEFormGetCollection($oIE, 0) ; Get first form by index $oSelect = _IEFormElementGetObjByName($oForm, "metakeyselect") Do Sleep(100) $sValue = _IEFormElementGetValue($oSelect) Until $sValue <> "#NONE#" $oInput = _IEFormElementGetObjByName($oForm, "metakeyinput") _IEFormElementSetValue($oInput, $sValue) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
jones Posted July 15, 2010 Author Posted July 15, 2010 (edited) It is running into a infinite loop with an error --> IE.au3 V2.4-0 Error from function _IEFormElementGetValue, $_IEStatus_InvalidDataType. Do you mind if I PM the screenshot of the form along with the entire source code. I went through a post that suggests me to solve in a different way. http://www.autoitscript.com/forum/index.php?showtopic=27212 Does the post help me in any way in setting value of the optionfield. Edited July 15, 2010 by jones
PsaltyDS Posted July 15, 2010 Posted July 15, 2010 I didn't expect the code I posted to work literally with your form. It just illustrates the technique. Probably _IEFormElementGetValue() fails because _IEFormElementGetObjByName() didn't succeed in getting $oSelect. The most likely cause of that is $oForm not being correct, because _IEFormGetCollection($oIE, 0) failed or got the wrong form. You have to do the following: 1. Get a valid reference to IE in $oIE, either by _IECreate() or by _IEAttach() 2. Get a valid reference to the form, which may mean drilling down into a parent form or frame 3. Get a valid reference to "metakeyselect" select element. 4. Get a valid reference to "metakeyinput" input element. How to do that depends on the particular web page you are working with. Time to bust out the help file and learn to use the functions. The following tips will help: A. Add _IEErrorHandlerRegister() to the top of the script. B. Run your script from SciTE so the error messages are easy to read in the console pane. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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