Jump to content

Javascript Submit Error


Go to solution Solved by big_daddy,

Recommended Posts

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
Link to comment
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

Link to comment
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. 
Link to comment
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

Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment
Share on other sites

  • Moderators

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

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
Link to comment
Share on other sites

  • Moderators
  • Solution

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

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...