Jump to content
Sign in to follow this  

[SOLVED] How to do an automated click on a javascript link in IE?

Recommended Posts



First of all, just wanted to say this is a great forum. Thanks to the online documentation and search function I solved many, many problems without having to post each time here.

However, this time I'm stuck.

I want my program to click on a javascript link in IE and read this can be done by including the IE.au3 in my script. I can't work with pixelsearch in this case and mouse coordinates won't work in this case either. However, the help file confuses me when it comes to functions such as _IEAction and the general handling of IE objects (completely new to this).

Here's the part of the website I want to click on (actually on the "add comment" link):

<table border="0" cellpadding="0" cellspacing="1" width="540">
<form method="post">
<td colspan="5" align="right"><a href="java script:openModalPopup('addnotes.do?accId=12345&deptId=1','',500,400)">Add Comment</a></td>

All the script has to do is to click on the "add comment" link. Once that happens a popup shows up and then I can use controlsend to paste text into it. Sadly, I lack the knowledge of this object stuff to do it myself.

Can anyone enlighten me? :)

Edited by Automania

Share this post

Link to post
Share on other sites

Thanks, that's a start. Sadly, the forum does not allow to search for "IE" and the results I found were either even more confusing or not close to my problem (unlike the link you provided).

I took a look at the help file regarding the _IELinkClickByText function. The way the example code worked it may or may not work with the website I have in mind. However, there's the next problem:

$oIE = _IECreate("http://www.autoitscript.com")

$sMyString = "wallpaper"
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkText = _IEPropertyGet($oLink, "innerText")
    If StringInStr($sLinkText, $sMyString) Then
        _IEAction($oLink, "click")

So due to the first line of code this script opens the autoit homepage first in IE and then searches for the link.

However, my website cannot be opened by autoit, it needs to be opened by the user in advance. That's because the first site of that website shows a search mask and the user has to type in a database entry (differs each time) to get to the window with the link that should be clicked by the script.

Is there a way to just search for the link and click it without opening the website by autoit and leave that to the user? I left out the $oIE = ... line but then it says the variable is not declared, what's the mistake here?

Edited by Automania

Share this post

Link to post
Share on other sites

_IELinkClickByText($oIE, "Add Comment")

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

Hey guys,

Thank you very much for your help, finally I knew where to start and look. It took a bit more searches and trial&error since the link I wanted to click was in an extra frame apparently.

Anyways, in case someone ever searches for a similar problem/solution I want to post the solution to my problem:

$oIE = _IEAttach("WebsiteTitle")
$oFrame = _IEframegetobjbyname($oIE,"noteframe")
_IELinkClickByText ( $oFrame, "Add Comment")

WebsiteTitle = the name of the title shown in IE (here: AutoIt Forums), will differ depending on the website, of course.

noteframe = apparently the name of the frame which included the link (found this out by looking at the the source code of the website), this might differ for other websites?

Again, thank you. Besides having found a nice, working solution I also learned something valuable about this DOM stuff. :) It appears quite abstract but I'm glad it's working now.

Next goal: getting the same thing to work in Firefox. >_< As far as I read I need a special script + a Firefox plugin. Wish me luck. :idiot:

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