Sign in to follow this  
Followers 0
crashnburn

Javascript Submit Error

22 posts in this topic

#1 ·  Posted (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?
 
#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 by crashnburn

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by crashnburn

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

Post your script with the debug lines where you placed them.

Share this post


Link to post
Share on other sites

#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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Thank you for the clarification! I will try it out and post results!

Share this post


Link to post
Share on other sites

I implemented your section and received:

==> Incorrect number of parameters in function call.:
ConsoleWrite(_IEPropertyGet($oTag))
ConsoleWrite(^ ERROR

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Strange that one of the HTMLInputElement doesn't have a .value property.  Post the html?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

That worked perfect!!! Thank you all so so so very much.

Share this post


Link to post
Share on other sites

You're welcome!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0