Sign in to follow this  
Followers 0
trdunsworth

Non-standard naming convention and trying to hit a button

6 posts in this topic

I'm working on a program that allows my users to input information in a GUI and then hit a button and write that information two places. So far, for each of the html pages it has to write to, I've had no problems. When it comes to reaching the screen to enter orders of protection, I run into a snag. All of the other pages they need are accessible from a dropdown menu at the top of the page. (I did not write the html I have to access, just as an fyi) However, for this one, I have to click a button on a main frame in the page, which will lead to another page, with another button. However, here's the rub. The button does not have a name, it has a submitName as a custom HTML attribute.

<button submitName="Orders Of Protection" style="width: 135px; height: 30px;" onclick="bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')" type="button" oldbackgroundcolor="buttonface" oldtextcolor="">

My code to reach it works. I am using a similar template and in testing a base code, it tells me that there's no match for the submitName attribute, but it doesn't argue with the drill down to reach it.

#include <IE.au3>

If WinActivate("REJIS - HOME") = 0 Then
   MsgBox(0, "Error", "The REJIS Home Window is not open. Please re-open it and re-submit the request.")
   Exit
EndIf
WinActivate("REJIS - HOME")
Local $oIE1 = _IEAttach("REJIS - HOME")
Local $oFrame1 = _IEFrameGetObjByName($oIE1, "MAIN")
Local $oFrame2 = _IEFrameGetObjByName($oFrame1, "HOMEBOTTOM")
Local $oBtn1 = _IEGetObjByName($oFrame2, "Orders of Protection")
_IEAction($oBtn1, "click")

This is test code only to reach that specific button. The production code is much longer so I am submitting the test.

The <button> is embedded in 3 framesets to get to the "MAIN" frame, then 1 frameset to get to the "HOMEBOTTOM" frame, then inside that frame's body tag, it is in a table, 3rd row, 3rd cell in the row. (I don't know if I'm allowed to expose all of the html by contract.) which makes it fun to find and I do not have a name or an id attribute in the buttons, the table or any of the table's descendents.

Any ideas on how to find it so I can click it? (Without going to the website authors and asking them to please write better html....)

Share this post


Link to post
Share on other sites



Grab all buttons, and loop through until one of the attributes matches what's present.

1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Or  $oIe.document.querySelector('button[submitname="Orders Of Protection"]').click()

IE 9+ required.

1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Nice.  Never knew about this...I can modify my signature to use this...it even returns object collections, and no more need for recursion...perfect.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

I started messing around with the first suggestion and got fed up and just did MouseClick inside the button. (Setting the mouse coordinates to inside the IE Window.)

I tried the $oIE1.document.querySelector, but I think I did something wrong because it didn't do anything, but exited with 0, so I'm guessing it's programmer error at this stage....

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It gives you the function name:

onclick="bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')"

;I'd try using something like:
Execute("$oFrame2.document.parentwindow.eval(""bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')"")")
;or
Execute("$oFrame2.document.parentwindow.execScript(""bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')"")")
 
;If that doesn't work:
Execute("$oFrame2.parentwindow.eval(""bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')"")")
;or
Execute("$oFrame2.parentwindow.execScript(""bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')"")")
 
;And If that doesn't work:
Execute("$oFrame2.document.eval(""bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')"")")
;or
Execute("$oFrame2.document.execScript(""bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')"")")
 
;And if still that doesn't work:
Execute("$oFrame2.eval(""bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')"")")
;or
Execute("$oFrame2.execScript(""bClicked('submenu.htm?ref=OOPMENU', 'Orders Of Protection')"")")
Edited by SmOke_N
1 person likes this

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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