Jump to content

IE UDF advice


Recommended Posts

Hello,

I'm attempting to automate an IE webpage that seems to use javascript and is quite complex. First, I need a way to find the correct "form" on the page.

$s_URL = http://www.website.com/
$o_IE = _IECreate($s_URL)
$o_Form = _IEFormGetObjByName($o_IE, "formNameThatINeed!")

Viewing the source or using the ie udf function "_IEDocReadHTML" isn't really helpful, since I'm looking at like over a thousand lines of code, and there doesn't appear to be any form names listed...

Would using something like this work?

$oIE = _IECreate (http://www.website.com/)
$oForms = _IEFormGetCollection ($oIE)

Or are these "forms" something different than what I would need?

Thanks. Please let me know if more information is needed.

Edited by shea851
Link to comment
Share on other sites

Checking out debugbar now.. it looks promising. Thanks a lot for the suggestion.

Well, I'm able to use debugbar to find the form name of anything on the page, which seems useful, except that according to Autoit, there are no forms on the page. Wtf?

Just to humor myself I went ahead and ran this function:

$oIE = _IECreate ("http://usd/CAisd/pdmweb.exe")
$oForms = _IEFormGetCollection ($oIE)
MsgBox(0, "Forms Info", "There are " & @extended & " forms on this page")
For $oForm In $oForms
    MsgBox(0, "Form Info", $oForm.name)
Next

It tells me there are 0 forms on the page. Debugbar says otherwise.

Here's my original code that doesn't work, because I can't specify a correct form.

$sRequestNum = "R1234567"

Func _USDtest($sRequestNum)
    $s_URL = ("http://usd/CAisd/pdmweb.exe")
    $o_IE = _IECreate($s_URL)
    $o_Form = _IEFormGetObjByName($o_IE, "goBtnForm")
    $o_RequestInputField = _IEFormElementGetObjByName($o_Form, "searchKey")
    _IEFormElementSetValue($o_RequestInputField, $sRequestNum)    
    _IEFormSubmit($o_Form)
    SetError(0)
    Return 1
EndFunc

And here's what Debugbar gives me for the form name:

<FORM name=goBtnForm

And when I run the script, here's what I get:

--> IE.au3 V2.4-0 Warning from function _IEFormGetObjByName, $_IEStatus_NoMatch

Am I going about this all wrong or are there just some webpages that aren't possible to automate? Because.. I'm pretty sure this should be working.

Edited by shea851
Link to comment
Share on other sites

You are likely being fooled by Frames or iFrames. If your form is in a frame it will not be found in the top level document and you need to use _IEFrame* functions to get a reference to the correct container.

Easiest way to find frames using DebugBar is to click on the "View Source" icon on the DebugBar toolbar (blue document icon with <> over it).

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

Dale.. I was being fooled by frames. The code below works perfectly for what I was trying to do. Now that I know the basics of working with the IE UDF as well as the specific webpage I hopefully shouldn't need to request further help here. Thanks everyone for your input.

Inputs a request number and clicks the search button.

$sRequestNum = "R1234567"

_USDtest($sRequestNum)

Func _USDtest($sRequestNum)
    $s_URL = "http://usd/CAisd/pdmweb.exe"
    $o_IE = _IECreate($s_URL)
    $o_Frame = _IEFrameGetObjByName ($o_IE, "gobtn")
    $o_Form = _IEFormGetObjByName($o_Frame, "goBtnForm")
    $o_RequestInputField = _IEFormElementGetObjByName($o_Form, "searchKey")
    _IEFormElementSetValue($o_RequestInputField, $sRequestNum)    
    $o_SubmitButton = _IEGetObjByName($o_Form, "imgBtn0_button")
    _IEAction($o_SubmitButton, "click")
    SetError(0)
    Return 1
EndFunc
Edited by shea851
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...