Jump to content

Internet Explorer button click help


Recommended Posts

Hi,

I've installed the latest AutoIt Beta (v.1.1.131) and I'm trying to work with the IE UDF.

We have an internal intranet site that is used as our Helpdesk. On this webpage, there is a refresh this page button. I am trying to automate the clicking of this button using AutoIT. The page is already loaded, and I just want to select the existing Internet Explorer instance without loading a fresh instance of IE. Please note this is a different button from the standard IE Refresh page button on the IE toolbar.

From doing a view source on the page, I can see the following line that I assume is the code associated with the refresh page button:

<input type=submit value="Refresh This Page" style="width:100%;margin-top:.4em">

I have attempted to write the following code to try and get the button press automated, but it's not working:

$oIE = WinActivate("List All Tickets - Microsoft Internet Explorer")
$oSubmit = _IEGetObjByName ($oIE, "submit")
_IEAction ($oSubmit, "click")
_IELoadWait ($oIE)

The above code sets the focus to the correct IE instance, but then it errors from the $oSubmit line onwards.

I'm a total newb to this, so please be gentle ;-)

Thanks in advance for any advice or help you can give me.

Kind Regards,

Greg.

Link to comment
Share on other sites

  • Moderators

Use

_IEAttach ("List All Tickets - Microsoft Internet Explorer")

Instead of win activate. If it still doesn't work then post again, but this is most likely the only problem.

Close, but there were a couple other things wrong also.

$oIE = _IEAttach ("List All Tickets - Microsoft Internet Explorer")
If @error Then
    MsgBox(48, "Error", "There was a problem attaching to the browser.")
    Exit
EndIf
; This assumes that it is the first form in source order
$oForm = _IEFormGetCollection($oIE, 0)
; This loop will execute until the IE Window is closed
While WinExists(_IEPropertyGet($oIE, "hwnd"))
    _IEFormSubmit($oForm)
    ; Adjust this for how often you want it to refresh
    Sleep(5000)
WEnd
Link to comment
Share on other sites

Wow! Thanks for the ultra swift response ;-)

big_daddy: I tried your suggested script and it seems to run OK, however the page is not refreshing. If I hover my mouse over the AutoIT icon near the clock, it says the script is paused?

Am I doing something wrong here?

Thanks,

Greg.

Link to comment
Share on other sites

  • Moderators

Wow! Thanks for the ultra swift response ;-)

big_daddy: I tried your suggested script and it seems to run OK, however the page is not refreshing. If I hover my mouse over the AutoIT icon near the clock, it says the script is paused?

Am I doing something wrong here?

Thanks,

Greg.

As you can see from the comments in my code you may need to change the below line.

; This assumes that it is the first form in source order
$oForm = _IEFormGetCollection($oIE, 0)

The "0" represents the first form on the page in source order, "1" would be the second, and so on.

Link to comment
Share on other sites

  • Moderators

Thank-you. I tried incrementing that number 0 through 10 and it still does the same thing - i.e. it didn't work.

Is there any way of working out what that number should be set to?

Thanks,

Greg.

This should tell you:

#include <IE.au3>

$oIE = _IEAttach ("List All Tickets - Microsoft Internet Explorer")
If @error Then
    MsgBox(48, "Error", "There was a problem attaching to the browser.")
    Exit
EndIf

$oForms = _IEFormGetCollection($oIE)

$i = 0
For $oForm In $oForms
    If StringInStr($oForm.innerHTML, _
        '<input type=submit value="Refresh This Page" style="width:100%;margin-top:.4em">') Then
    MsgBox(0, "", "Your form is: " & $i)
    EndIf
Next
Link to comment
Share on other sites

Hello, welcome to the forums...

I imagine that you are just anxious to see SOMETHING work at this point, so give this code a shot:

$oIE = _IEAttach ("List All Tickets - Microsoft Internet Explorer")
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput in $oInputs
    If $oInput.value = "Refresh This Page" Then
        _IEAction($oInput, "click")
        ExitLoop
    EndIf
Next

It is a more complicated way of approaching the issue than is normally used, but with the information you provided it should work.

The way that this is typically done is to first get the name of the form that contains the button you want to click. You'll find a <FORM> tag that contains either a NAME= or ID= value -- it is that value you would use for _IEFormGetObjByName.

Most forms have a name, but some don't... if yours doesn't you can use the technique that big_daddy used with getting a form reference by index using _IEFormGetCollection. Form indexes are reference the form objects on the page in the order that they appear in the HTML source, starting with 0.

If you only have one TYPE=SUBMIT form element in the form, you can then use _IEFormSubmit to activate the refresh button. If this is the case, big_daddy's example should work for you simply by correcting the index of the form in _IEFormGetCollection.

If there is more than one TYPE=SUBMIT button in the form or if there is a Javascript onclick event tied to it you may still need to click the button. Once you have a reference to the form, you can use it in _IEFormElementGetObjByName or _IEFormElementGetCollection to get a reference to the specific form element inside the form. Since your refresh button doesn't have a name, you'll need to use the _IEFormElementGetCollection using the same logic as with _IEFormGetCollection. Once you have this reference you can use it with _IEAction and "click" as you did in your first attempt.

Hopefully this gives you some more foundation moving forward.

Dale

Edit: added missing "}" in example

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

Link to comment
Share on other sites

Hi Guys,

Thanks so much for your help.

I tried Big Daddy's solution and the script just runs and then closes without popping any messages.

Dale: your script generates the following error:

AutoIt Error

Line 4 (File"C:\Scripts\Refresh.au3")

$oInputs = _IETagNameGetCollection($oIE, "input"

$oInputs=^ERROR

Error: Error parsing function call.

I've searched through the page's code by doing a view source in IE, and I can only find one instance of TYPE=SUBMIT

Is there something funny with the way this page is written maybe? I may be able to post some of this code, but obviously I have to be careful about what I can share online.

Thanks,

Greg.

Link to comment
Share on other sites

Dale: your script generates the following error:

I noticed a missing ")" and fixed it within seconds of the initial post, but you were too quick. Please try again.

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

OK, thanks Dale ;-)

Now it runs through, but the script just disappears. What should I expect it to do?

Thanks,

Greg.

It is expected to do whatever happens when you click the "Refresh This Page" button with the mouse.

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

OK, well it isn't working then.

When I actually click the button it takes a few seconds to refresh, but this is not happening when I run these scripts.

OK, there is something else going on then. We've only gotten to see one line in your HTML file so far so we are just making guesses. You'll need to dig into it more, try to understand the logic of the IE.au3 functions, figure out what is unique about your page and then come back here with more questions as appropriate.

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

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