peterchua89 Posted November 9, 2014 Posted November 9, 2014 Dear All Expert, I have a question regarding "_IEGetObjById" if i would like my Form to automatically select from a Div Class, how should my AutoIT coding be? I cant seem to get the section inside Div ID. This is the HTML example of coding that i would like auto it to fill it in automatically. </div> <div id="listing"> <div class="form_line"> <div class="heading">Listing</div> <div class="comment">Choose type.</div> <table class="splitter"> <tr> <td class="field"> <select class="statuses" id="classified_ad_listing" name="classified_ad[listing]"><option selected="selected" value="For Sale">For Sale</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option></select> </td> <td class="extra" id='ad_auction'> <label class="checkbox" for="classified_ad_auction"> <input name="classified_ad[auction]" type="hidden" value="0" /><input id="classified_ad_auction" name="classified_ad[auction]" type="checkbox" value="1" /> Auction </label> </td> </tr> </table> </div> </div> This is the coding that i come out with, #include <IE.au3> Local $oIE = _IECreate("_Example") _IELoadWait($oIE) Local $oDiv = _IEGetObjById ($oIE, "listing") Local $oForm = _IEFormGetObjByName($oIE, "classified_ad_listing") Local $oSelect = _IEFormElementGetObjByName($oForm, "classified_ad_listing") _IEAction($oSelect, "focus") For $i = 1 To 10 _IEFormElementOptionSelect($oSelect, "2", 1, "byText") Next Would like to select for example <option value="2">2</option> Im kind of new in coding actually, apologize if its a bit awkward / weird coding.
Moderators SmOke_N Posted November 9, 2014 Moderators Posted November 9, 2014 Your request doesn't show more than you putting in a few things here and there into example code. What errors are you getting? Where is this "form" you're working with? You're using "id's" for some functions that show "name". A url would be helpful, especially since most of the items there have class names, it may be easier to work that way. Anyway, put your URL you're working with in this code, and test from there. #include <IE.au3> Global $go_IE = _IECreate("URLHere") ; no need for load wait, we have 1 in the load wait paramater ; of _IECreate as default _IE_ObjErrorCheck($go_IE, "_IECreate Error", @error, @extended) Global $go_DivListing = _IEGetObjById($go_IE, "listing") _IE_ObjErrorCheck($go_DivListing, "Could not get Listing object", @error, @extended) ; Note, this is get object by name, not get object by id Global $go_AdListing = _IEGetObjByName($go_DivListing, "classified_ad[listing]") _IE_ObjErrorCheck($go_FormAdListing, "Could not get Ad Listing object", @error, @extended) If Not _IEFormElementOptionSelect($go_AdListing, "2", 1, "byText") Then MsgBox(16 + 262144, "Error", "Option not selected, error code: " & @error) Exit 2 EndIf Func _IE_ObjErrorCheck($o_obj, $s_error, $n_error, $n_extended, $b_exit = True) If Not IsObj($o_obj) Then MsgBox(16 + 262144, "Error", "Error: " & $n_error & @CRLF & _ "Extended: " & $n_extended & @CRLF & @CRLF & _ $s_error) If $b_exit Then Exit 1 EndIf EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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