crashnburn Posted June 9, 2013 Share Posted June 9, 2013 (edited) I have setup a script to automate some router tasks. Everything works but at the end of the script I get an error message: The requested action with this object has failed.: If String($oTag.Value) = "Apply" Then If String($oTag.Value^ ERROR Everything in the script works it just gives this popup message at the end. Any idea of how to fix it? expandcollapse popup#include <IE.au3> $sUsername = "user" $sPassword = "password" $input=inputbox("Select", "Disabled, Allow, or Deny?") Sleep(1000) $oIE = _IECreate("192.168.0.1", 0, 0) sleep(3000) $oform = _IEFormGetCollection($oIE, 0) $ologin = _IEFormElementGetObjByName($oform, "loginUsername") $opassword = _IEFormElementGetObjByName($oform, "loginPassword") _IEFormElementSetValue($ologin, $sUsername) _IEFormElementSetValue($opassword, $sPassword) _IEFormSubmit($oform) Sleep(2000) _IELinkClickByIndex($oie,5) sleep(2000) _IELinkClickByIndex($oIE, 13) $oForm = _IEFormGetCollection($oIE, 0) Sleep(1000) $oSelect = _IEFormElementGetObjByName($oForm, "MacRestrictMode") Sleep(1000) Select Case $input = "Disabled" _IEFormElementOptionSelect($oSelect, 0, 1, "byIndex");Disabled Case $input = "Allow" _IEFormElementOptionSelect($oSelect, 1, 1, "byIndex");Allow Case $input = "Deny" _IEFormElementOptionSelect($oSelect, 2, 1, "byIndex");Deny EndSelect Sleep(1000) $oTags = _IETagNameGetCollection($oIE, "input") For $oTag In $oTags If String($oTag.Value) = "Apply" Then _IEAction($oTag, "click") _IELoadWait($oIE) EndIf Next Edited June 9, 2013 by crashnburn Link to comment Share on other sites More sharing options...
DaleHohm Posted June 10, 2013 Share Posted June 10, 2013 Add some diagnostics before the If statement, like: ConsoleWrite(IsObj($oTag)) ConsoleWrite(_IEPropertyGet($oTag)) ConsoleWrite(ObjName($oTag)) 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...
crashnburn Posted June 10, 2013 Author Share Posted June 10, 2013 (edited) Will do! Thank you very much for the reply! I won't be able to test for a couple hours, but I will post results as soon as possible. Edited June 10, 2013 by crashnburn Link to comment Share on other sites More sharing options...
crashnburn Posted June 11, 2013 Author Share Posted June 11, 2013 So I inserted your code example before the if statement and after the $oTags declaration. It gave me this error: ==> Variable used without being declared.: ConsoleWrite(IsObj($oTag)) ConsoleWrite(IsObj(^ ERROR To test it I declared it at the begging of the script and received a incorrect parameters error. I am at a lose as to what to do next. Link to comment Share on other sites More sharing options...
DW1 Posted June 11, 2013 Share Posted June 11, 2013 Post your script with the debug lines where you placed them. AutoIt3 Online Help Link to comment Share on other sites More sharing options...
crashnburn Posted June 11, 2013 Author Share Posted June 11, 2013 expandcollapse popup#include <IE.au3> $sUsername = "user" $sPassword = "password" Dim $oTag ;This was not in my first attempt, but my second $input=inputbox("Select", "Disabled, Allow, or Deny?") Sleep(1000) $oIE = _IECreate("192.168.0.1", 0, 0) sleep(3000) $oform = _IEFormGetCollection($oIE, 0) $ologin = _IEFormElementGetObjByName($oform, "loginUsername") $opassword = _IEFormElementGetObjByName($oform, "loginPassword") _IEFormElementSetValue($ologin, $sUsername) _IEFormElementSetValue($opassword, $sPassword) _IEFormSubmit($oform) Sleep(2000) _IELinkClickByIndex($oie,5) sleep(2000) _IELinkClickByIndex($oIE, 13) $oForm = _IEFormGetCollection($oIE, 0) Sleep(1000) $oSelect = _IEFormElementGetObjByName($oForm, "MacRestrictMode") Sleep(1000) Select Case $input = "Disabled" _IEFormElementOptionSelect($oSelect, 0, 1, "byIndex");Disabled Case $input = "Allow" _IEFormElementOptionSelect($oSelect, 1, 1, "byIndex");Allow Case $input = "Deny" _IEFormElementOptionSelect($oSelect, 2, 1, "byIndex");Deny EndSelect Sleep(1000) $oTags = _IETagNameGetCollection($oIE, "input") ConsoleWrite(IsObj($oTag)) ConsoleWrite(_IEPropertyGet($oTag)) ConsoleWrite(ObjName($oTag)) For $oTag In $oTags If String($oTag.Value) = "Apply" Then _IEAction($oTag, "click") _IELoadWait($oIE) EndIf Next Link to comment Share on other sites More sharing options...
DW1 Posted June 11, 2013 Share Posted June 11, 2013 Oh I see. He was asking for you to put them in the for loop where oTag will be declared. $oTags = _IETagNameGetCollection($oIE, "input") For $oTag In $oTags ConsoleWrite(IsObj($oTag)) ConsoleWrite(_IEPropertyGet($oTag)) ConsoleWrite(ObjName($oTag)) If String($oTag.Value) = "Apply" Then _IEAction($oTag, "click") _IELoadWait($oIE) EndIf Next AutoIt3 Online Help Link to comment Share on other sites More sharing options...
crashnburn Posted June 11, 2013 Author Share Posted June 11, 2013 Thank you for the clarification! I will try it out and post results! Link to comment Share on other sites More sharing options...
crashnburn Posted June 11, 2013 Author Share Posted June 11, 2013 I implemented your section and received: ==> Incorrect number of parameters in function call.: ConsoleWrite(_IEPropertyGet($oTag)) ConsoleWrite(^ ERROR Link to comment Share on other sites More sharing options...
DW1 Posted June 11, 2013 Share Posted June 11, 2013 I implemented your section and received: ==> Incorrect number of parameters in function call.: ConsoleWrite(_IEPropertyGet($oTag)) ConsoleWrite(^ ERROR Hmm not sure what property he meant to ask for. Just remove that line for now. See what the other two return at that point. AutoIt3 Online Help Link to comment Share on other sites More sharing options...
crashnburn Posted June 11, 2013 Author Share Posted June 11, 2013 Removed that line and now I receive: 1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElement1HTMLInputElementC:\Router.au3 (40) : ==> The requested action with this object has failed.: If String($oTag.Value) = "Apply" Then If String($oTag.Value^ ERROR Link to comment Share on other sites More sharing options...
DW1 Posted June 11, 2013 Share Posted June 11, 2013 Strange that one of the HTMLInputElement doesn't have a .value property. Post the html? AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted June 11, 2013 Moderators Share Posted June 11, 2013 I see you are using _IELoadWait after the click action. If the page refreshes then your collection object $oTags would be destroyed. You could use the @Extended value to get the count and then reference each element by index value within a loop. Link to comment Share on other sites More sharing options...
DW1 Posted June 11, 2013 Share Posted June 11, 2013 I see you are using _IELoadWait after the click action. If the page refreshes then your collection object $oTags would be destroyed. You could use the @Extended value to get the count and then reference each element by index value within a loop. Nice catch, I didn't know that would destroy the object, but for cleanup, sure makes a lot of sense. So OP should be okay as long as once he clicks Apply and does the _IELoadWait, he then calls ExitLoop right? Like this? For $oTag In $oTags If String($oTag.Value) = "Apply" Then _IEAction($oTag, "click") _IELoadWait($oIE) ExitLoop EndIf Next AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Moderators Solution big_daddy Posted June 11, 2013 Moderators Solution Share Posted June 11, 2013 I was thinking of something more like this. _IETagNameGetCollection($oIE, "input") $iTagCount = @extended For $i = 0 To $iTagCount - 1 $oTag = _IETagNameGetCollection($oIE, "input", $i) If String($oTag.Value) = "Apply" Then _IEAction($oTag, "click") _IELoadWait($oIE) EndIf Next Link to comment Share on other sites More sharing options...
crashnburn Posted June 11, 2013 Author Share Posted June 11, 2013 That worked perfect!!! Thank you all so so so very much. Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted June 11, 2013 Moderators Share Posted June 11, 2013 You're welcome! Link to comment Share on other sites More sharing options...
DaleHohm Posted June 11, 2013 Share Posted June 11, 2013 For the record, what I intended for ) _IEPropertyGet($oTag) was _IEPropertyGet($oTag, "outerhtml") 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...
crashnburn Posted June 11, 2013 Author Share Posted June 11, 2013 Thank you all again for the help. I have been trying to do some research on the "@extended" to see why and when it would be used. I read some posts on this forum and also the help file but I cannot wrap my head around it. Would anyone mind breaking down this section for me: $iTagCount = @extended For $i = 0 To $iTagCount - 1 Or even just point me in the right direction to learn more about it. I am a self taught autoit user so some of the terminology is over my head, so any newbie guide would be great The closest thing I have found to break it down was >this post, but I didn't get an idea of when to use this over the other options. Thank you all again very much! Link to comment Share on other sites More sharing options...
crashnburn Posted June 11, 2013 Author Share Posted June 11, 2013 Also, I was very excited to see your posts on here Dale. It was thanks to a post you helped with on how to control forms I read a couple months ago that got me started on Autoit, so thank you very much for that! 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