Jump to content

Trying to click a button


Recommended Posts

Good day folks,

I'm trying to write a script which will open a page, go down to the right table, and click the only button which is in that table. (I didn't write the site, I just have to work with it.

I can get to the page just fine and I'm certain I've drilled into the right table. I just can't click the bloody button.

The HTML code for that table and it is the 6th table on the page (so I'm aiming, when I post my script code for index 5)

<table>
<tbody>
<tr>
</td/>
<td>
<button style="width: 135px; height: 30px;" onclick="bClicked('Mules_Inq/mules_prop_gun_inq_frame.htm', 'Gun Inquiry')" type="button">
</td>
<td />
</tr>
</tbody>
</table>

My script code so far:

#include <IE.au3>
AutoItSetOption("WinTitleMatchMode",2)
$winhandle=WinActivate("REJIS - ")
$oIE=_IEAttach("REJIS")
$o_IEFrame=_IEFrameGetObjByName($oIE,"MENUFRAME")
$o_form=_IEFormGetCollection($o_IEFrame,0)
$o_pages=_IEFormElementGetObjByName($o_form,"pages")
;_IEFormElementOptionSelect($o_pages,"Address Inquiry",1,"byText")
_IEFormElementOptionSelect($o_pages,"NCIC Property - Guns",1,"byText")
$oIE2=_IEAttach("REJIS - NCIC Property - Guns")
$o_IE2Frame=_IEFrameGetObjByName($oIE2,"MAIN")
$o_table=_IETableGetCollection($o_IE2Frame,5)
$o_inquiry=_IEGetObjByName($o_table, "Gun Inquiry")
_IEAction($o_inquiry,"click")

This allows me to get to the page, but the button isn't being clicked. I know I'm new at this, so I'm hoping I can get pointed to the right direction to fix this issue.

Thanks,

Tony

Link to comment
Share on other sites

Hi and Welcome to the Forums!

Focusing on the last 4 lines of your example...

$o_IE2Frame=_IEFrameGetObjByName($oIE2,"MAIN")
$o_table=_IETableGetCollection($o_IE2Frame,5)
$o_inquiry=_IEGetObjByName($o_table, "Gun Inquiry")
_IEAction($o_inquiry,"click")

_IEGetObjByName() doesn't allow a table object as the first or any of its properties. If you check the help file it says it needs to be an IE Application, Window or Frame object.

Luckily, you've got $o_IE2Frame as your frame object (hopefully) so skip getting any reference to the table and use your frame object in place of the table object in the _IEGetObjByName() function. So give this a shot...

$o_IE2Frame=_IEFrameGetObjByName($oIE2,"MAIN")
;$o_table=_IETableGetCollection($o_IE2Frame,5)  ;Comment this out
;$o_inquiry=_IEGetObjByName($o_table, "Gun Inquiry")    ;Comment this out and use the next line instead
$o_inquiry=_IEGetObjByName($o_IE2Frame, "Gun Inquiry")   ;use $o_IE2Frame as first parameter
_IEAction($o_inquiry,"click")

Edit/add: OOPS just realized "Gun Inquiry" isn't going to be the name of your button...if it's public can you provide a link to this page?

Edited by MrMitchell
Link to comment
Share on other sites

Yea I'm not too good at this...but back to those same 4 lines, try this...

$o_IE2Frame=_IEFrameGetObjByName($oIE2,"MAIN")  ;Get the frame
$o_table=_IETableGetCollection($o_IE2Frame,5)  ;Get the table in the frame
;The next line added
$o_button = _IETagNameGetCollection($o_table, "button", 0)   ;Get the first button in the table (index 0)
;$o_inquiry=_IEGetObjByName($o_table, "Gun Inquiry")   ;Comment this out because the previous line should have the button
_IEAction($o_inquiry,"click")
Link to comment
Share on other sites

Yea I'm not too good at this...but back to those same 4 lines, try this...

$o_IE2Frame=_IEFrameGetObjByName($oIE2,"MAIN")  ;Get the frame
$o_table=_IETableGetCollection($o_IE2Frame,5)  ;Get the table in the frame
;The next line added
$o_button = _IETagNameGetCollection($o_table, "button", 0)   ;Get the first button in the table (index 0)
;$o_inquiry=_IEGetObjByName($o_table, "Gun Inquiry")   ;Comment this out because the previous line should have the button
_IEAction($o_inquiry,"click")

We ended up doing it this way

$oIE2=_IEAttach("REJIS - NCIC Property - Guns")
$o_IE2Frame=_IEFrameGetObjByName($oIE2,"MAIN")
$oButtons=_IETagNameGetCollection($o_IE2Frame,"button")
For $oButton in $oButtons
    Switch $oButton.name
        Case "Gun Inquiry"
            $o_BtnGunInquiry=$oButton
    EndSwitch
Next
_IEAction($o_BtnGunInquiry,"click")

However, I'm going to test yours as well because if it works the way I think it should, I like the shorter code.

Thanks agian for the help!! :mellow:

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...