Sign in to follow this  
Followers 0
mpcluever

Clicking on a javascript button

8 posts in this topic

Trying to click a javascript button on a webpage in IE. Here's the source:

<TD style="display:none" id="tdBtnAccount" width="16%" bgcolor="white">
            <DIV id="div1" width="100%" class="lmNormal"><A class="lmNormal" id="button1" href="Javascript:Navigate('button1','/access/account.aspx','div1')">Account</A></DIV>
        </TD>

I've lost track of everything I've tried. There's 3 different "id" labels in there. Assuming I can target the button based on name, which one should I be aiming at?

Trying to target that link/button keeps failing.

_IELinkClickByText($oIE, "Account")
_IELinkClickByText($oIE, "tdBtnAccount")
_IELinkClickByText($oIE, "div1")
$AccountButton = _IEGetObjById($oIE, "Account")
$AccountButton = _IEGetObjById($oIE, "tdBtnAccount")
$AccountButton = _IEGetObjById($oIE, "div1")
$oSubmit = _IEGetObjByName ($oIE, "tdBtnAccount")
$oSubmit = _IEGetObjByName ($oIE, "Account")
$oSubmit = _IEGetObjByName ($oIE, "div1")
_IELinkClickByIndex ($oIE, 2)

I get:

--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
--> IE.au3 V2.4-0 Warning from function _IEGetObjById, $_IEStatus_NoMatch (Account)
--> IE.au3 V2.4-0 Warning from function _IEGetObjById, $_IEStatus_NoMatch (tdBtnAccount)
--> IE.au3 V2.4-0 Warning from function _IEGetObjById, $_IEStatus_NoMatch (div1)
--> IE.au3 V2.4-0 Warning from function _IEGetObjByName, $_IEStatus_NoMatch (Name: tdBtnAccount, Index: 0)
--> IE.au3 V2.4-0 Warning from function _IEGetObjByName, $_IEStatus_NoMatch (Name: Account, Index: 0)
--> IE.au3 V2.4-0 Warning from function _IEGetObjByName, $_IEStatus_NoMatch (Name: div1, Index: 0)
--> IE.au3 V2.4-0 Warning from function _IELinkClickByIndex, $_IEStatus_NoMatch

For reference, here's how I'm getting there:

$oIE = _IECreate("http://www.amphire.com/access/custompages/rsi/logon.aspx")
$oForm = _IEFormGetObjByName($oIE, "formLogon")
$oText = _IEFormElementGetObjByName($oForm, "vsLogonName")
_IEFormElementSetValue($oText, $RSI_Username)
$oPassword = _IEFormElementGetObjByName($oForm, "vsPassword")
_IEFormElementSetValue($oPassword, $RSI_Password)
_IEFormSubmit($oForm)
_IELinkClickByText($oIE, "Distributor Ordering")

Share this post


Link to post
Share on other sites



Clicking by mousecoords in the window?

Share this post


Link to post
Share on other sites

Really want to avoid mouse clicks if at all possible. The script would be run on a couple other people's machines.

$oButton = _IEGetObjById($oIE,"button1")
_IEAction($oButton,"Click")

results in:

--> IE.au3 V2.4-0 Warning from function _IEGetObjById, $_IEStatus_NoMatch (button1)
--> IE.au3 V2.4-0 Error from function _IEAction, $_IEStatus_InvalidDataType

Share this post


Link to post
Share on other sites

Try ConsoleWrite(_IEDocReadHTML($oIE)) to insure the document contains the source you think it does.

Look for frames.

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

Here's the top part of the page source if that helps. I'm not great with reading html, but get the jist of it. The button I need is about 2/3 down.

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'><HTML>
<HEAD>
    <TITLE>Access</TITLE>
<META HTTP-EQUIV='PRAGMA' CONTENT='NO-CACHE'><META NAME='MS.LOCALE' CONTENT='en-us' /></HEAD>
<script language='Javascript' src='/access/script/formValidation.js'></SCRIPT>
<script language='Javascript' src='/access/script/listFunctions.js'></SCRIPT>
<script language='Javascript' src='/access/script/global.js'></SCRIPT>
<script language='Javascript' src='/access/script/xmldom.js'></SCRIPT>
<script language='Javascript' src='/access/script/modxml.js'></SCRIPT>
<LINK REL=stylesheet href='/assets/style/global.css' type=text/css>
<LINK REL=stylesheet href='/assets/style/RH.css' type=text/css><BODY onload="if(parent.frames.length==0) parent.location='welcome.aspx';">
<IFRAME id="budgetIframe" name="budgetIframe" style="DISPLAY: none; Z-INDEX: 1; LEFT: 350px; WIDTH: 405px; POSITION: absolute; TOP: 150px;HEIGHT:85px" marginheight="0" marginwidth="0" noresize frameborder="yes" scrolling="no" src=/access/blank.aspx?sessionKey=zMQA7cmHeVL4FE1nS2%2bLp4qh3O4h5SVhAZ4bw9U%2fryiY5%2fxs5xaVk5%2fp%2fkWyYG7sGHPCX0Nhp50OpmON9dGZPF4fiO4YT0Vezk0Az6JvF%2f4yMX8%2fO7MsZl06wPIfG%2b4nBWGJnaDRKZPhTNo5h24nWLqT05YlW6nUMlgppC4HQfejneGZqWQGY4RGf6zHb4Ij></IFRAME>

<FORM name="formMenu" action="/access/frmBrowse.aspx?sessionKey=zMQA7cmHeVL4FE1nS2%2bLp4qh3O4h5SVhAZ4bw9U%2fryiY5%2fxs5xaVk5%2fp%2fkWyYG7sGHPCX0Nhp50OpmON9dGZPF4fiO4YT0Vezk0Az6JvF%2f4yMX8%2fO7MsZl06wPIfG%2b4nBWGJnaDRKZPhTNo5h24nWLqT05YlW6nUMlgppC4HQfejneGZqWQGY4RGf6zHb4Ij" method="get" target="frmMain" onSubmit="goSearch(); return false;">
    <TABLE cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
        <TR>
            <TD width="100%" colspan="3">
<TABLE cellpadding="0" cellspacing="1" width="100%" class="siteBG">
    <TR align="middle" class="siteBG">
        <TD style="display:none" id="tdBtnHome" width="16%" bgcolor="white"><DIV  id='div0' width='100%' class='lmClick'><A class=lmClick id=button0 href='javascript:GoRsi();'>Home</A></DIV></TD></TD>
        <TD style="display:none" id="tdBtnAccount" width="16%" bgcolor="white">
            <DIV id="div1" width="100%" class="lmNormal"><A class="lmNormal" id="button1" href="Javascript:Navigate('button1','/access/account.aspx','div1')">Account</A></DIV>
        </TD>
        <TD style="display:none" id="tdBtnOrderMenu" width="16%" bgcolor="white">
            <DIV id="div2" width="100%" class="lmNormal"><A class="lmNormal" id="button2" href="Javascript:Navigate('button2','/access/ordermenu.aspx','div2')">Order</A></DIV>
        </TD>
        <TD style="display:none" id="tdBtnCart" width="16%" bgcolor="white">
            <DIV id="div3" width="100%" class="lmNormal"><A class="lmNormal" id="button3" href="Javascript:Navigate('button3','/access/cart.aspx', 'div3')">Cart</A></DIV>
        </TD>
        <TD style="display:none" id="tdBtnCheckOut" width="16%" bgcolor="white">
            <DIV id="div4" class="lmNormal"><A class="lmNormal" id="button4" href="Javascript:Navigate('button4','/access/checkout.aspx?cStage=Exception', 'div4')">Submit</A></DIV>
        </TD>
    </TR>
</TABLE>
<script language="Javascript">

Share this post


Link to post
Share on other sites

And how did you obtain the HTML you showed?

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

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