Sign in to follow this  
Followers 0
Bert

Trouble scripting a IE window

21 posts in this topic

#1 ·  Posted (edited)

I'm having some trouble scripting this website:

https://www.fedex.com/AltRefTracking?ascend...sh&altref=y

All I'm looking to do is paste a string in the Reference window, then click on the track button. I've been trying to use the _IE commands, as well as trying out examples to see how to do it, but I guess I'm just not getting it. Either I get a error, or it doesn't see anything. No code to post for it is just a few lines I keep changing just to see if I can find the control.

Edited by vollyman

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You're going to hate this......

open the url

17 TABs

CTRL+V

7 Tabs

Enter.

Not the answer you wanted, but it works.

Edited by System Tester

The AutoIt help file should be interrogated.The Editor should be SciTe.The forums should have been searched.

Share this post


Link to post
Share on other sites

You are wrong.

I'm working on a FedEx Tracking function as we speak, but it may have to wait until I get back from lunch.

Share this post


Link to post
Share on other sites

This should do what you need.

#include <IE.au3>

$sTrackNum = "987654321" ;Tracking numbers
$sAcctNum = "123456789" ;Account Number
$iShipMonth = 1 ;1 = JAN, 12 = DEC
$iShipDay = 2 ;Day of the month (1-31)
$iShipYear = 2004 ;Shipped year (2004, 2005, or 2006)
$sDestCntry = "us" ;Destination Country (us = United States)
$iDestPostal = 65536 ;Destination postal code

_FedExTracking($sTrackNum, $sAcctNum, $iShipMonth, $iShipDay, $iShipYear, $sDestCntry, $iDestPostal)

Func _FedExTracking($s_TrackNum, $s_AcctNum = "", $i_ShipMonth = @MON, $i_ShipDay = @MDAY, $i_ShipYear = @YEAR, $s_DestCntry = "", $i_DestPostal = "")
    $s_URL = "https://www.fedex.com/AltRefTracking"
    $o_IE = _IECreate($s_URL)
    $o_Form = _IEFormGetObjByName($o_IE, "tracking")
    $o_AcctNum = _IEFormElementGetObjByName($o_Form, "account_number")
    $o_TrackNum = _IEFormElementGetObjByName($o_Form, "tracknumbers")
    $o_ShipMonth = _IEFormElementGetObjByName($o_Form, "shipMonth")
    $o_ShipDay = _IEFormElementGetObjByName($o_Form, "shipDay")
    $o_ShipYear = _IEFormElementGetObjByName($o_Form, "shipYear")
    $o_DestCntry = _IEFormElementGetObjByName($o_Form, "dest_cntry")
    $o_DestPostal = _IEFormElementGetObjByName($o_Form, "dest_postal")
    
    If $s_AcctNum = "" And $s_DestCntry = "" Then
        ConsoleWrite("You must provide either an account number or destination country." & @CR)
        SetError(1)
        Return 0
    EndIf
    
    _IEFormElementSetValue($o_AcctNum, $s_AcctNum)
    _IEFormElementSetValue($o_TrackNum, $s_TrackNum)
    _IEFormElementOptionselect($o_ShipMonth, $i_ShipMonth)
    _IEFormElementOptionselect($o_ShipDay, $i_ShipDay)
    _IEFormElementOptionselect($o_ShipYear, $i_ShipYear)
    _IEFormElementOptionselect($o_DestCntry, $s_DestCntry)
    _IEFormElementSetValue($o_DestPostal, $i_DestPostal)
    
    _IEFormSubmit($o_Form)
    SetError(0)
    Return 1
EndFunc   ;==>_FedExTracking

Share this post


Link to post
Share on other sites

I'm beginning to understand if the object I'm trying to interact with is a Java script object, I'm out of luck. Please correct me if I'm wrong. (PLEASE let me be wrong... :whistle: )

Looks pretty straight forward from an IE.au3 perspective to me... I think this does what you want...

#include <IE.au3>

$oIE = _IECreate("https://www.fedex.com/AltRefTracking?ascend_header=1&clienttype=dotcom&cntry_code=us&language=english&altref=y")

$trackingNumber = "12345678"

$oForm = _IEFormGetObjByName($oIE, "tracking")
$oRef = _IEFormElementGetObjByName($oForm, "tracknumbers")
_IEFormElementSetValue($oRef, $trackingNumber)
_IEFormSubmit($oForm)

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

I ended up adding a couple of things, but it now does exactly what I need:

$oIE = _IECreate("https://www.fedex.com/AltRefTracking?ascend_header=1&clienttype=dotcom&cntry_code=us&language=english&altref=y")
    $trackingNumber = ClipGet()
    $oForm = _IEFormGetObjByName($oIE, "tracking")
    $oRef = _IEFormElementGetObjByName($oForm, "tracknumbers")
    $o_DestCntry = _IEFormElementGetObjByName($oForm, "dest_cntry")
    _IEFormElementSetValue($oRef, $trackingNumber)  
    _IEFormElementOptionselect($o_DestCntry, "us")  
    _IEFormSubmit($oForm)

Share this post


Link to post
Share on other sites

New problem, different page. It is internal, but I can post the source for the page.

I know it is a link, but I can't get a handle on it.

This is the sourcecode for the page:

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Matching Orders for your Search</title>

<script language="Javascript" type="text/javascript">

<!--

document._domino_target = "_self";

function _doClick(v, o, t) {

var url="/SunTrack/DepotNew.nsf/0/f1b47a5b1d7c2e7585257219006fc370?OpenDocument&Click=" + v;

if (o.href != null)

o.href = url;

else {

if (t == null)

t = document._domino_target;

window.open(url, t);

}

}

// -->

</script>

</head>

<body text="#000000" bgcolor="#FFFFFF">

<form action="">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr valign="top"><td width="100%" bgcolor="#808080"><b><font size="5" color="#ffffff" face="Arial">Matching Orders for your Search</font></b></td></tr>

</table>

<!-- Begin LotusScript Generated HTML --><H3>Your Search Yielded 1 Results.</H3><P><TABLE BORDER=1><TR><TH>Order Number</TH><TH>CTS Contact</TH><TH>Client Name</TH><TH>Shipping Address</TH><TH>Problem Description</TH></TR><TR><TD><A HREF="/SunTrack\DepotNew.nsf/0/BE0F2BB6FF8C7A41852572100070AAB1?OpenDocument&Login">DPT20061023-MH1923</A></TD><TD>XXXXXXXXXXX</TD><TD>XXXXXXXXXX</TD><TD>XXXXXXXXX<BR>XXXXXXXXXXXXX<BR>XXXXXXXXXXXXXX</TD><TD></TD></TR></TABLE><!-- End LotusScript Generated HTML --><br>

</form>

</body>

</html>

The code that I'm using to get to this point is this:

clipput("DPT20061023-MH1923")
$web = "http://atlnotes1.stsc.suntrust.com/SunTrack/DepotNew.nsf/SearchOrders?OpenForm"
$web_2 = "Depot Ordering System - Search Orders"
#include <IE.au3>
$oIE = _IECreate ($web)
WinWaitActive($web_2, $web, 5)
WinWaitActive($web_2, "Done", 5)
    Sleep(100)
$trackingNumber = ClipGet() 
$oForm = _IEFormGetObjByName($oIE, "_SearchOrders")
$oRef = _IEFormElementGetObjByName($oForm, "GeneralSearch")
_IEFormElementSetValue($oRef, $trackingNumber)
_IEFormSubmit ($oForm, 0)
WinWaitActive("Matching Orders for your Search", "Done", 50)
$oIE =  WinGetHandle("Matching Orders for your Search", "Done")
_IELinkClickByIndex($oIE, 1)

I'm getting a error: --> IE.au3 Error from function _IELinkClickByIndex, $_IEStatus_InvalidDataType

It looks like a link, and the source says it is a link. ???????? :whistle:;) ??????????

Share this post


Link to post
Share on other sites

You get $_IEStatus_InvalidDataType from _IELinkClickByIndex because you are passing in an invalid datatype (surprising huh :whistle: )

You start out right with $oIE = _IECreate ($web) and $oIE is an object variable. Just before the end however you do a $oIE = WinGetHandle("Matching Orders for your Search", "Done") - this turns $oIE into a handle (HWND). _IELinkClickByIndex needs an object variable, not a handle.

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

#13 ·  Posted (edited)

I saw the window change names, and I thought I needed to go with that. From what you are saying, the window name once opened with $oIE = _IECreate ($web) makes no difference. It has a ID on the window itself, which in this case is a object variable.

Edited by vollyman

Share this post


Link to post
Share on other sites

The first thing I would try is _IEAttach().

Share this post


Link to post
Share on other sites

Ok, that makes sence. The one thing I'm still not sure of in this window is how to find the controls. It is written in Java, so I'm not sure what to look for in the source. I have some input boxes I want to interact with. Dale was telling me even if the page is written in Java, there is still a base where I can get to the controls. :whistle:

CODE
<!-- static const char* const POPUP_FRAMES_RCSID = "@(#)$Id: popup_frames.html,v 1.26.1.5 2003/03/20 00:27:20 jenji01 Exp $";-->

<!-- popup_frames.htmpl was changed to popup_frames.html -->

<HTML>

<script LANGUAGE="Javascript">

function get_ahdtop()

{

if ( typeof parent.ahdtop == "object" &&

parent.ahdtop != null &&

! parent.ahdtop.closed ) {

window.ahdtop = parent.ahdtop;

return window.ahdtop;

}

else {

for ( var win = window; typeof win == "object"; win = win.opener ) {

if ( win == null ||

win.closed ||

typeof win.name != "string" )

// we may not have a good object here, so get out

break;

if ( typeof win.ahdtop == "object" &&

win.ahdtop != null &&

! win.ahdtop.closed ) {

window.ahdtop = win.ahdtop;

return window.ahdtop;

}

while ( win != win.parent &&

win.name != "AHDtop" &&

! win.parent.closed &&

typeof win.parent.name == "string" ) {

win = win.parent;

}

if ( win.name == "AHDtop" ) {

window.ahdtop = win;

return window.ahdtop;

}

}

}

window.ahdtop = void(0);

return window.ahdtop;

}

var ahdtop = get_ahdtop();

if ( typeof ahdtop != "object" )

alert("Can't find ahdtop in popup_frames.html");

else {

cfgCAISD = ahdtop.cfgCAISD;

propSupportR50 = ahdtop.propSupportR50;

var styleTag = "<"+"LINK REL='stylesheet' TYPE='text/css' HREF='";

var endStyle = "'>\n";

var scriptTag = "<"+"SCRIPT LANGUAGE='Javascript' SRC='";

var endScript = "'><"+"/SCRIPT>\n";

document.write(styleTag + ahdtop.usdStyles["styles_ahd"] + endStyle);

document.write(styleTag + ahdtop.usdStyles["imgbutton"] + endStyle);

document.write(scriptTag + ahdtop.usdScripts["browser"] + endScript);

document.write(scriptTag + ahdtop.usdScripts["window_manager"] + endScript);

document.write(scriptTag + ahdtop.usdScripts["imgbutton"] + endScript);

document.write(scriptTag + ahdtop.usdScripts["sitemods"] + endScript);

}

function load_initial_url()

{

if ( window.cai_main.document.URL.indexOf("empty.html") == -1 )

return;

var popunder = false;

if ( typeof ahdtop == "object" &&

typeof ahdtop.popup_frames_info == "object" &&

window.location.search.match(/POPUP_URLIX=(\d+)/) ) {

var ix = RegExp.$1 - 0;

var info = ahdtop.popup_frames_info[ix];

if ( typeof info == "object" ) {

cfgInitialURL = info.url;

popunder = info.popunder;

if ( info.name != "" )

window.name = get_popup_window_name(info.name);

else {

var w_name = get_next_window_name();

if ( popunder ) {

w_name = "popunder" + w_name;

w_name = w_name.replace(/USD/,"");

}

window.name = w_name;

}

}

ahdtop.popup_frames_info[ix] = void(0);

if ( ( typeof cfgInitialURL != "string" ||

cfgInitialURL.length == 0 ) &&

typeof ahdtop.lastClosedURL == "string" )

cfgInitialURL = ahdtop.lastClosedURL;

}

register_window(window);

if ( ! popunder )

window.focus();

if ( typeof cfgInitialURL == "string" &&

cfgInitialURL.length > 0 ) {

if ( cfgInitialURL.match(/^(.*)\+actWinName=(\w*)(.*)$/) ) {

actWinName = RegExp.$2;

cfgInitialURL = RegExp.$1 + RegExp.$3;

}

display_new_page( window.cai_main.document.location,

cfgInitialURL, true );

window.gobtn.document.location.replace( ahdtop.usdHTML["gobtn"] );

}

else {

alert("Internal error in popup_frames.html determining which page to load - please retry");

window.close();

}

}

function doClose()

{

self.close();

}

var is_form_loaded = false;

</SCRIPT>

</HEAD>

<script LANGUAGE="Javascript">

document.writeln("<FRAMESET ROWS='50,28,*' FRAMEBORDER='0' FRAMESPACING='0' BORDER='0' onload='load_initial_url()' onunload='cancel_window()'>");

document.writeln("<FRAMESET COLS='*,1,1' FRAMEBORDER='0' FRAMESPACING='0' BORDER='0'>");

document.writeln("<FRAME SRC='" + cfgCAISD +

"/html/empty.html' NAME=gobtn NORESIZE SCROLLING=no marginheight=0 marginwidth=0 FRAMEBORDER=NO BORDER=0>");

document.writeln("<FRAME SRC='" + ahdtop.usdHTML["top_splash"] +

"' NAME=top_splash NORESIZE SCROLLING=NO MARGINHEIGHT=0 MARGINWIDTH=0 FRAMEBORDER=NO BORDER=0>");

document.writeln("<FRAME SRC='" + cfgCAISD +

"/html/empty.html' NAME=workframe NORESIZE=NORESIZE MARGINHEIGHT=0 MARGINWIDTH=0 FRAMEBORDER=NO BORDER=0>"); // Do not modify!!!

document.writeln("</FRAMESET>");

document.writeln("<FRAME SRC='" + ahdtop.usdHTML["menubar"] +

"' NAME=menubar NORESIZE SCROLLING=no marginheight=0 marginwidth=0 FRAMEBORDER=NO BORDER=0>");

document.writeln("<FRAME SRC='" + cfgCAISD +

"/html/empty.html' NAME=cai_main SCROLLING=" +

( _browser.isIE && propSupportR50 != "yes" ? "no" : "auto" ) +

" MARGINHEIGHT=0 MARGINWIDTH=0 FRAMEBORDER=NO BORDER=0>");

document.writeln("</FRAMESET>");

</SCRIPT>

</HTML>

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Please be careful with terminology. That is not Java, it is Javascript. Best quote about that is that the only similarity between the two is the first four letters of their names.

The content on that page is dynamically generated and is not represented by what you see in view source - therefore use the following command to reveal what the real state of the DOM is:

ConsoleWrite(_IEDocReadHTML($oIE) & @CR)

You will see that there is a frameset involved. Please read about the _IEFrame* functions.

Dale

Edit: Typos

Edited by DaleHohm

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

Tried this, and it errored out.

$web_a = "New Incident - Unicenter ServicePlus Service Desk"
WinActivate($web_a)
$oIE =_IEAttach($web_a)
$oForms = _IEFormGetCollection ($oIE)
MsgBox(0, "Forms Info", "There are " & @extended & " forms on this page")
For $oForm In $oForms
    MsgBox(0, "Form Info", $oForm.name)
    ConsoleWrite(_IEDocReadHTML($oIE) & @CR)
Next

--> IE.au3 Error from function _IEFormGetCollection, $_IEStatus_InvalidDataType

Share this post


Link to post
Share on other sites

I'm betting there were other messages written to the console than the one you supplied. Please provide complete information or you will frustrate those attempting to help you.

Please read the helpfile for _IEAttach more carefully as well -- if this is a popup, you need to use the "popup" or "embedded" parameters.

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

#20 ·  Posted (edited)

Actually, there wasn't. I was hoping there were. I did noticed that there are certain js files when I looked at the source, and I managed to capture this just a little while ago with tweaking the script.

I would suspect, though I haven't looked in them yet, the answer I need is there Edited by vollyman

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