nobbe Posted March 15, 2008 Share Posted March 15, 2008 (edited) i am trying to enter data in an entry field which is triggered by some javascript / ajax #include <IE.au3> ;$sUrl = "www.dizzler.com/music/C" $sUrl = "www.dizzler.com" $oIE = _IECreate($sUrl, 1) $this_form_name = "searchform"; $oForm = _IEFormGetObjByName($oIE, $this_form_name); the form name $form_edit_obj = _IEFormElementGetObjByName($oForm, "q"); name of the ENTRY field ; now set the values to fields _IEFormElementSetValue($form_edit_obj, "abba"); _IEFormSubmit($oForm); the HMTL code of the section CODE <form id="searchform" name="searchform" class="noinit" action="/music/" method="get" onsubmit="Dizzler_Search(); return false;"> <input type="hidden" name="media" value="mp3" /> <div style="background:url(new/newImages/search_bg.gif) top left no-repeat; width:395px; height:65px; margin:0px; padding-left:2px;"> <input name="q" id="q" type="text" onclick="Searchbar_Click();" onblur="Searchbar_UnClick();" style="font-size: 16px;line-height: 17px; width:322px;margin: 5px 5px 0px 3px;" maxlength="50" onkeyup="SA(this.value);" onkeydown="sbkd(event);" value="" disableautocomplete=1 autocomplete="off" /> <input name="searchbtn" id="searchbtn" type="submit" value=" " style="background: url(new/newImages/btn_search.gif) top left no-repeat; width:36px; height:36px; border:none; cursor:pointer;" /> <br /> <table style="margin-left: 5px;" cellpadding=0 cellspacing=0 border=0 id="radiobtns"> <tr> <td id="mtype_music" class="searchmode" style="background-color:#555555; margin-top: 0px;" onclick="return setSearchType('music');">Music</td> <td id="mtype_video"class="searchmode" onclick="return setSearchType('video');">Video</td> <td class="searchmode" onclick="document.location.href='/';" style="font-size:13px; border-right:0px;">more</td> </tr> </table> </div> </form> Edited March 15, 2008 by nobbe Link to comment Share on other sites More sharing options...
FreeFry Posted March 15, 2008 Share Posted March 15, 2008 (edited) I did some testing on that site, and I can't get _IEFormElementSetValue to work, but _IEFormElementGetValue works fine. :S However, I managed to set it with java script: #include <ie.au3> $ieObj = _IECreate("http://www.dizzler.com/") $formObj = _IEFormGetObjByName($ieObj, "searchform") $inputObj = _IEFormElementGetObjByName($formObj, "q") _IEAction($inputObj, "click") _IENavigate($ieObj, 'java script:void(document.searchform.q.value="Test")', 0) You need to set focus on the element first, but _IEAction($inputObj, "focus") didn't work, but "click" does. Edit: uhm, remove the space between java and script... forum keeps adding it >_> Edited March 15, 2008 by FreeFry Link to comment Share on other sites More sharing options...
nobbe Posted March 15, 2008 Author Share Posted March 15, 2008 hi thanks for leading me in the direction , this was really tricky.. the following code works for me now CODE#include <IE.au3> $sUrl = "http://www.dizzler.com/" $oIE = _IECreate($sUrl, 1) $formObj = _IEFormGetObjByName($oIE, "searchform") $inputObj = _IEFormElementGetObjByName($formObj, "q") $searchvalue = "phil collins" _IEAction($inputObj, "click") ; activate object first _IENavigate($oIE, 'java script:void(document.searchform.q.value="' & $searchvalue & '"' & ')', 0); ; submit button as entry field?? $submitObj = _IEFormElementGetObjByName($formObj, "searchbtn") _IEAction($submitObj, "click") ; ;_IEFormSubmit($formObj); doesnt work here.. Link to comment Share on other sites More sharing options...
FreeFry Posted March 15, 2008 Share Posted March 15, 2008 Good to hear you got it working. Yeah, ie automation can be a little tricky sometimes. :/ Link to comment Share on other sites More sharing options...
DaleHohm Posted March 15, 2008 Share Posted March 15, 2008 Just for the record, _IEFormElementSetValue is doing what it is asked to do. The value actually gets set and if you watch carefully you can see it flash into the field and then immediately get removed. There is a lot of Javascript tied to that form element: <INPUT id=q onkeydown="return sbkd(event);" onblur=Searchbar_UnClick(); onkeyup=SA(this.value); style="BORDER-RIGHT: #7e7c7c 1px solid; BORDER-TOP: #7e7c7c 1px solid; FONT-WEIGHT: bold; BORDER-LEFT: #7e7c7c 1px solid; WIDTH: 400px; COLOR: #888888; BORDER-BOTTOM: #7e7c7c 1px solid" onclick=Searchbar_Click(); maxLength=50 name=q autocomplete="off" disableautocomplete="disableautocomplete"> The source of your trouble is that in addition to setting the field value, _IEFormElementSetValue also fires two events on the field: onchange and onclick. It is likely the onclick that is activating some code that is clearing the field again. Fortunately, _IEFormElementSetValue allows you to turn off the firing of these events with an optional parameter. So, this works: #include <IE.au3> $sUrl = "http://www.dizzler.com/" $oIE = _IECreate($sUrl, 1) $formObj = _IEFormGetObjByName($oIE, "searchform") $inputObj = _IEFormElementGetObjByName($formObj, "q") $submitObj = _IEFormElementGetObjByName($formObj, "searchbtn") $searchvalue = "phil collins" _IEAction($inputObj, "click") ; activate object first _IEFormElementSetValue($inputObj, $searchvalue, 0) _IEAction($submitObj, "click") Thanks, that was an interesting problem. 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...
nobbe Posted March 15, 2008 Author Share Posted March 15, 2008 thanks for pointing it out the ",0)" was probably the trigger that let the value set as is without firing the additional javascript _IEFormElementSetValue($inputObj, $searchvalue, 0) the ajax in the server seems to set the values to the nearest matching possibility. try with $searchvalue = "phil coll" etc... to see what happens greetings nob 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