vladqa Posted March 14, 2008 Share Posted March 14, 2008 Hello there, I'm a new into scripting and very new into AutoIt. But I have a question that someone might have time to answer (as it's most likely very simple one). I have a web page (see Source Code of the page bellow), and I'm trying to make my script to select a value from "Product" and enter a Name into "User Name". No luck so far - I know I'm missing something (and/or misusing some of ) but I'm not sure what am I doing wrong... (and I tried differetn scenarious). Here is Source Code: =================================== <html> <head> <title>TCV Login</title> <script src="/formL.js"></script> <script language="Javascript"> <!-- function validateForm (form) { requiredSelect = new Array("product"); selectDisplay = new Array("Product"); requiredText = new Array("login"); textDisplay=new Array("User Name"); return requireSelects(form, requiredSelect, selectDisplay, 0) && requireValues( form, requiredText, textDisplay ); } //--> </script> </head> <body background="/images/goodpaper.gif" property="fixed"> <img src="/images/logo.gif"><br> <h3 align="center"><font color="darkolivegreen" size=+2>TCView (Test Case Document System) </font></h3> <hr> <br> <form method="post" action=/index.cgi onsubmit="return validateForm(this)" > <table align='center' background="/images/goodpaper.gif" border="0" cellspacing="2" cellpadding="2" cols="1"> <tr><td><b>Product</b></td> <td><b>:</b></td> <td> <select name="product" size=4> <option>PP1</option> <option>PP2</option> <option>SS0</option> <option>MMS</option> </select> </td> </tr> <tr><td><b>User Name</b></td> <td><b>:</b></td> <td><input type="text" name="login"> </td></tr> </table> <hr> <p align="center"> <input type="Submit" name="submit" value="Login" style="font-size:16px;border-width:1;border:solid;background-color:#fffddd;color:#000080"> </font> <input type="hidden" name="displaystatus" value="ok"> </form> </body> </html>=================================== Here is my code: $oIE = _IECreate() _IENavigate($oIE, $url, 0) $sHTML = _IEDocReadHTML($oIE) $oForm = _IEFormGetObjByName($oIE, "action=/index.cgi") $oProduct = _IEFormElementGetObjByName ($oForm, "product") _IEFormElementOptionselect ($oProduct, "PP1") $oQuery = _IEFormElementGetObjByName($oForm, "login") _IEFormElementSetValue($oQuery, "testUser") _FileWriteLog(@ScriptDir & "\my2.log", $oForm) Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 14, 2008 Share Posted March 14, 2008 Hello there, I'm a new into scripting and very new into AutoIt. But I have a question that someone might have time to answer (as it's most likely very simple one). I have a web page (see Source Code of the page bellow), and I'm trying to make my script to select a value from "Product" and enter a Name into "User Name". No luck so far - I know I'm missing something (and/or misusing some of ) but I'm not sure what am I doing wrong... (and I tried differetn scenarious). Here is my code: $oIE = _IECreate() _IENavigate($oIE, $url, 0) $sHTML = _IEDocReadHTML($oIE) $oForm = _IEFormGetObjByName($oIE, "action=/index.cgi") $oProduct = _IEFormElementGetObjByName ($oForm, "product") _IEFormElementOptionselect ($oProduct, "PP1") $oQuery = _IEFormElementGetObjByName($oForm, "login") _IEFormElementSetValue($oQuery, "testUser") _FileWriteLog(@ScriptDir & "\my2.log", $oForm) That Form does not appear to have a name property set on it, so I doubt "action=/index.cgi" is matching. If it really is the first form on the page then use _IEFormGetCollection($oIE, 0) instead. If you put _IEErrorHandlerRegister() at the top of the script you will get very informative error information that probably would point right to that. 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 Link to comment Share on other sites More sharing options...
vladqa Posted March 14, 2008 Author Share Posted March 14, 2008 That Form does not appear to have a name property set on it, so I doubt "action=/index.cgi" is matching. If it really is the first form on the page then use _IEFormGetCollection($oIE, 0) instead. If you put _IEErrorHandlerRegister() at the top of the script you will get very informative error information that probably would point right to that. Thanks a lot PsaltyDS, for your prompt reply!! Here is what I did (I hope that what you suggested) and what I got in the SciTE console (still having problem). Does it mean that my page actually has no Form and I should use something else instead??? The SourceCode of the page is what this page contains. I'm a bit confused what DataType it requires and if my understanding of using $fCol is correct (as it seems to have no value assigned to it). And most likely I'm not sure what should be use for the Form to Match (where I can get it from) as well as for the other _IEForm* ... Thanks once again and in advance. My new code: _IEErrorHandlerRegister() $oIE = _IECreate($url) $sHTML = _IEDocReadHTML($oIE) $fCol = _IEFormGetCollection($oIE, 0) $oForm = _IEFormGetObjByName($oIE, $fCol) $oProduct = _IEFormElementGetObjByName ($oForm, "product") _IEFormElementOptionselect ($oProduct, "PP1") $oQuery = _IEFormElementGetObjByName($oForm, "login") _IEFormElementSetValue($oQuery, "testUser") _FileWriteLog(@ScriptDir & "\my2.log", $oForm) _FileWriteLog(@ScriptDir & "\my3.log", $fCol) Here is what I'm getting in SciTE console: ----------------------------------------------------------- IE.au3 V2.3-1 Warning from function _IEFormGetObjByName, $_IEStatus_NoMatch --> IE.au3 V2.3-1 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidDataType --> IE.au3 V2.3-1 Error from function _IEFormElementOptionselect, $_IEStatus_InvalidDataType --> IE.au3 V2.3-1 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidDataType --> IE.au3 V2.3-1 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType ----------------------------------------------------------- Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 14, 2008 Share Posted March 14, 2008 Thanks a lot PsaltyDS, for your prompt reply!! Here is what I did (I hope that what you suggested) and what I got in the SciTE console (still having problem). Does it mean that my page actually has no Form and I should use something else instead??? The SourceCode of the page is what this page contains. I'm a bit confused what DataType it requires and if my understanding of using $fCol is correct (as it seems to have no value assigned to it). And most likely I'm not sure what should be use for the Form to Match (where I can get it from) as well as for the other _IEForm* ... Thanks once again and in advance. My new code: _IEErrorHandlerRegister() $oIE = _IECreate($url) $sHTML = _IEDocReadHTML($oIE) $fCol = _IEFormGetCollection($oIE, 0) $oForm = _IEFormGetObjByName($oIE, $fCol) $oProduct = _IEFormElementGetObjByName ($oForm, "product") _IEFormElementOptionselect ($oProduct, "PP1") $oQuery = _IEFormElementGetObjByName($oForm, "login") _IEFormElementSetValue($oQuery, "testUser") _FileWriteLog(@ScriptDir & "\my2.log", $oForm) _FileWriteLog(@ScriptDir & "\my3.log", $fCol) Here is what I'm getting in SciTE console: ----------------------------------------------------------- IE.au3 V2.3-1 Warning from function _IEFormGetObjByName, $_IEStatus_NoMatch --> IE.au3 V2.3-1 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidDataType --> IE.au3 V2.3-1 Error from function _IEFormElementOptionselect, $_IEStatus_InvalidDataType --> IE.au3 V2.3-1 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidDataType --> IE.au3 V2.3-1 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType ----------------------------------------------------------- No, the _IEForGetObjectByName() is completely replaced by _IEFormGetCollection() and retreives $oForm for you: #include <IE.au3> Global $url = "http://www.who.knows.where.com" _IEErrorHandlerRegister() $oIE = _IECreate($url) $oForm = _IEFormGetCollection($oIE, 0) $oProduct = _IEFormElementGetObjByName($oForm, "product") _IEFormElementOptionselect($oProduct, "PP1") $oQuery = _IEFormElementGetObjByName($oForm, "login") _IEFormElementSetValue($oQuery, "testUser") 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 Link to comment Share on other sites More sharing options...
vladqa Posted March 14, 2008 Author Share Posted March 14, 2008 Actually I just tried to use: $fCol = _IEFormGetCollection($oIE, 1) -- which output me "2008-03-14 11:43:40 : 0" (instead of regular "2008-03-14 11:43:40 :") and makes me think that I need to use: $oForm = _IEFormGetObjByName($oIE, 0) This part WORKS !!!!! Thanks a lot PsaltyDS for hint!!!!!!!!!!!!!!!!! But I still have a 3 more questions (hopefully those are also quite simple, although might be quite dummy ) 1. How can I select i.e "SS0" (any other item from the list rather then just a very first one)?? Using: _IEFormElementOptionselect ($oProduct, "SS0") -- does not seem to be working. 2. How can I press "Login" button on this page. I'm using: $oSignin = _IEFormElementGetObjByName ($oForm, "submit") _IEAction($oSignin, "submit") --- but it does not seems to be working either. 3. What is "0" represnets in the "$oForm = _IEFormGetObjByName($oIE, 0)" (does it mean that there is no Form in this page??)? Please help!!! Thanks in advance!! My new code: _IEErrorHandlerRegister() $oIE = _IECreate($url) $sHTML = _IEDocReadHTML($oIE) $fCol = _IEFormGetCollection($oIE, 0) $oForm = _IEFormGetObjByName($oIE, 0) $oProduct = _IEFormElementGetObjByName ($oForm, "product") _IEFormElementOptionselect ($oProduct, "SS0") $oQuery = _IEFormElementGetObjByName($oForm, "login") _IEFormElementSetValue($oQuery, "testUser") $oSignin = _IEFormElementGetObjByName ($oForm, "submit") _IEAction($oSignin, "submit") _FileWriteLog(@ScriptDir & "\my2.log", $oForm) _FileWriteLog(@ScriptDir & "\my3.log", $fCol) Link to comment Share on other sites More sharing options...
vladqa Posted March 14, 2008 Author Share Posted March 14, 2008 No, the _IEForGetObjectByName() is completely replaced by _IEFormGetCollection() and retreives $oForm for you:CODE: AutoIt#include <IE.au3>Global $url = "http://www.who.knows.where.com"_IEErrorHandlerRegister()$oIE = _IECreate($url)$oForm = _IEFormGetCollection($oIE, 0)$oProduct = _IEFormElementGetObjByName($oForm, "product")_IEFormElementOptionselect($oProduct, "PP1")$oQuery = _IEFormElementGetObjByName($oForm, "login")_IEFormElementSetValue($oQuery, "testUser")Thanks PsaltyDS!!!! I guess I was too fast with my previous post What about 3 questions in my last post - is it easy (and does not take too much of your time) to answer? Greatly appreciated!!!Thanks once again & in advance!!!!! Link to comment Share on other sites More sharing options...
vladqa Posted March 14, 2008 Author Share Posted March 14, 2008 Here is what I'm getting in SciTE console for my Submit Action: --> IE.au3 V2.3-1 Error from function _IEAction, $_IEStatus_InvalidValue (Invalid Action) Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 14, 2008 Share Posted March 14, 2008 Actually I just tried to use: $fCol = _IEFormGetCollection($oIE, 1) -- which output me "2008-03-14 11:43:40 : 0" (instead of regular "2008-03-14 11:43:40 :") and makes me think that I need to use: $oForm = _IEFormGetObjByName($oIE, 0) This part WORKS !!!!! Thanks a lot PsaltyDS for hint!!!!!!!!!!!!!!!!! No, it doesn't. The correct code for getting $oForm is what I gave you. The returned value is an Object Variable, not 1 or 0 for success. Read the help file on this command. You shouldn't be trying to test success on an object by writing it to a file with _FileWriteLog(). Read the help file on OBJ/COM Reference. But I still have a 3 more questions (hopefully those are also quite simple, although might be quite dummy ) 1. How can I select i.e "SS0" (any other item from the list rather then just a very first one)?? Using: _IEFormElementOptionselect ($oProduct, "SS0") -- does not seem to be working. Use "byText" for the $s_mode parameter of that function. Read the help file on that command. 2. How can I press "Login" button on this page. I'm using: $oSignin = _IEFormElementGetObjByName ($oForm, "submit") _IEAction($oSignin, "submit") --- but it does not seems to be working either. There is no such action as "submit" with _IEAction(). Read the help file on that command. 3. What is "0" represnets in the "$oForm = _IEFormGetObjByName($oIE, 0)" (does it mean that there is no Form in this page??)?The 0 indicates the first of multiple possible matches. In this case, it would mean the first to match the Name. In my code, it means the first object in the collection of all Form objects. Read the help file on this command. Please help!!! Thanks in advance!! My new code: _IEErrorHandlerRegister() $oIE = _IECreate($url) $sHTML = _IEDocReadHTML($oIE) $fCol = _IEFormGetCollection($oIE, 0) $oForm = _IEFormGetObjByName($oIE, 0) $oProduct = _IEFormElementGetObjByName ($oForm, "product") _IEFormElementOptionselect ($oProduct, "SS0") $oQuery = _IEFormElementGetObjByName($oForm, "login") _IEFormElementSetValue($oQuery, "testUser") $oSignin = _IEFormElementGetObjByName ($oForm, "submit") _IEAction($oSignin, "submit") _FileWriteLog(@ScriptDir & "\my2.log", $oForm) _FileWriteLog(@ScriptDir & "\my3.log", $fCol)That is no way to test the success of an object variable. This kind of takes the tests to an extreme, but should show you more of what's going on, plus it has the Optionselect fixed:#include <IE.au3> Global $url = "http://www.who.knows.where.com" _IEErrorHandlerRegister() $oIE = _IECreate($url) If IsObj($oIE) Then ConsoleWrite("Debug: $oIE is an object. Type = " & ObjName($oIE) & @LF) $oForm = _IEFormGetCollection($oIE, 0) If IsObj($oForm) Then ConsoleWrite("Debug: $oForm is an object. Type = " & ObjName($oForm) & @LF) $oProduct = _IEFormElementGetObjByName($oForm, "product") If IsObj($oProduct) Then ConsoleWrite("Debug: $oProduct is an object. Type = " & ObjName($oProduct) & @LF) _IEFormElementOptionselect($oProduct, "PP1", 1, "byText") $oQuery = _IEFormElementGetObjByName($oForm, "login") If IsObj($oQuery) Then ConsoleWrite("Debug: $oQuery is an object. Type = " & ObjName($oQuery) & @LF) _IEFormElementSetValue($oQuery, "testUser") Else ConsoleWrite("Debug: Error: $oQuery is not an object.") EndIf Else ConsoleWrite("Debug: Error: $oProduct is not an object.") EndIf Else ConsoleWrite("Debug: Error: $oForm is not an object.") EndIf Else ConsoleWrite("Debug: Error: $oIE is not an object.") EndIf Now go read the help file. Run the excellent examples Dale put in there for the _IE* functions you are trying to use. 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 Link to comment Share on other sites More sharing options...
vladqa Posted March 14, 2008 Author Share Posted March 14, 2008 THANKS A LOT PsaltyDS for ALL your time and ALL your Help and Replies!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! It works now!!! Also thanks for the pointing out to use Help (as until now I've been using just Online documentation and I think those functions (_*) are missing there) but I can see it in the SciTE Help). Thanks once again for all your help and prompt reply and your time!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Very appreciated!!!!!!!!! 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