Jump to content

[Solved] Click on Text doesn't work for me...


Recommended Posts

<DIV class=NavSelect onclick="OnOpt('newfile.asp');">
  <DIV class=NavText>Text Link</DIV>
</DIV>
$oFrame = _IEFrameGetObjByName ($oIE, "options")
_IELinkClickByText ($oFrame, "Text Link")

I am trying to click on the "Text Link" in the upper html that is enclosed in a frame of the page I am trying to manipulate. The text isn't an actual HTML link as you can see, but I thought the click by text would work.

I have tried the lower code, but it doesn't move the mouse to the link or click it, or anything actually. _IEDocReadHTML shows that I have the right frame and the right HTML in the frame, so the text for the text link does exist.

Is there some other function I can use to do this? Maybe one that give me the coords of the text and I can move the mouse and click using the MouseClick function?

Thanks,

Bre

Edited by BreCalmor
Link to comment
Share on other sites

No, it's not stupid.

I'm not sure how to search by div text. At least, I don't know how to do that using the IE functions. I can whip up an XPath statement no problem but I don't know if XPath works in IE.

What is XPath?

Can I specify anything on the 'class=NavSelect' ???

Edited by BreCalmor
Link to comment
Share on other sites

  • Moderators

No, it's not stupid.

I'm not sure how to search by div text. At least, I don't know how to do that using the IE functions. I can whip up an XPath statement no problem but I don't know if XPath works in IE.

You can achieve it like this...

#include <IE.au3>

$sURL = "somewhere.com"
$sSearch = "Text Link"

$oIE = _IECreate($sURL)
$oFrame = _IEFrameGetObjByName($oIE, "options")
$oDivs = _IETagNameGetCollection($oFrame, "DIV")
For $oDiv In $oDivs
    If _IEPropertyGet($oDiv, "InnerText") = $sSearch Then
        _IEAction($oDiv, "click")
        _IELoadWait($oIE)
        ExitLoop
    EndIf
Next
Link to comment
Share on other sites

You can achieve it like this...

#include <IE.au3>

$sURL = "somewhere.com"
$sSearch = "Text Link"

$oIE = _IECreate($sURL)
$oFrame = _IEFrameGetObjByName($oIE, "options")
$oDivs = _IETagNameGetCollection($oFrame, "DIV")
For $oDiv In $oDivs
    If _IEPropertyGet($oDiv, "InnerText") = $sSearch Then
        _IEAction($oDiv, "click")
        _IELoadWait($oIE)
        ExitLoop
    EndIf
Next
That didn't work, the collection only had 1 record and it contained all the text in the entire frame, which has a tons of divs. I tried to narrow it down to the form, but it came up with nothing. The main DIV has an ID, should I try that and see what I get. [edit: didn't work at all...]

What else can I do?

Thanks,

Bre

Edited by BreCalmor
Link to comment
Share on other sites

Bump.

I am stuck until someone can figure this out.

Here is the bulk of the HTML:

<DIV class=NavDiv id=NavDiv><DIV class=NavSpacer></DIV>
<DIV class=NavMessage><FONT color=#ffcc00>Good Afternoon</FONT><BR><FONT color=#ffffff>Bre</FONT></DIV>
<DIV class=NavSpacer style="HEIGHT: 100px"></DIV>
<DIV class=NavSelect onclick="OnSentClick(this,'../link1.ASP');">
<DIV class=NavText>Text of Link1</DIV></DIV>
<DIV class=NavSpacer></DIV>
<DIV class=NavOption onclick="OnSentClick(this,'../link2.ASP');">
<DIV class=NavText>Text of Link2</DIV></DIV>
<DIV class=NavSpacer></DIV>
<DIV class=NavOption onclick="OnSentClick(this,'../link3.ASP');">
<DIV class=NavText>Text of Link3</DIV></DIV>
<DIV class=NavSpacer></DIV>
<DIV class=NavOption onclick="OnSentClick(this,'../link4.ASP');">
<DIV class=NavText>Text of Link4</DIV></DIV>
<DIV class=NavSpacer></DIV>
<DIV class=NavOption onclick=OnSentClick();>
<DIV class=NavText>Text of Link5</DIV></DIV>
<DIV class=NavSpacer></DIV></DIV>

I want to be able to click on the links using code no matter where they are on the screen instead of using coordinates... mainly because I will use this on more than one computer and the changing screen resolutions and IE toolbars are killing me.

Thanks,

Bre

Link to comment
Share on other sites

Well, if you really wanted to, you could run a regular expression on the whole block of text. I'm feeling a little depressed right now but if you know anything about regular expressions you can start on it yourself.

Actually, I have a question. Is that a copy and paste of the source? If so, that's a little questionable because of the missing "" around things like the class names.

Edited by Richard Robertson
Link to comment
Share on other sites

Well, if you really wanted to, you could run a regular expression on the whole block of text. I'm feeling a little depressed right now but if you know anything about regular expressions you can start on it yourself.

Ok, so I have a rough idea on regular expressions, but once I do that, what does it matter... I can't use click on text, it doesn't work...
Link to comment
Share on other sites

I wasn't going to say to click anything. I was suggesting you just analyze that block of text and pull out the links you want. That way you can just navigate to them instead.

Unfortunately, the links are not hard links, they are onclick events within DIV tags. I really am at a loss. All I am doing now is clicking at certain points on the screen [i.e. MouseClick ("left", 100/1280*@DesktopWidth, 305/1024*@DesktopHeight)].

Sorry if this seems simple, but I am having no luck.

Edited by BreCalmor
Link to comment
Share on other sites

That's why I was saying you would parse the physical text in the source using a regular expression. You could read for the onclick="whatever" and use the whatever.

I understand what your saying, but the _IEAction uses an element object, what function would I use to 'click' in your example? I know what the code is, it doesn't change. Edited by BreCalmor
Link to comment
Share on other sites

~sigh~

No. You use the Navagate function to go to the url that you copy out of the text.

Nope, won't work. I already tried that with hard coded links. The website restricts being able to do that. You can't even use F5 to refresh. You have to log back in and start all over.

That is why I need to use the mouse to click on the link, its just been hard to find a way to do that without just clicking on a location. I may just have to figure out the screen and calculate the location of the link on the screen based on the screen dimensions and the height of the visible toolbars, etc...

Thanks,

Bre

Link to comment
Share on other sites

I've made a small change to big_daddy's code (adding a String function).

Give it a try and see if it doesn't work for you...

Dale

#include <IE.au3>

$sURL = "somewhere.com"
$sSearch = "Text Link"

$oIE = _IECreate($sURL)
$oFrame = _IEFrameGetObjByName($oIE, "options")
$oDivs = _IETagNameGetCollection($oFrame, "DIV")
For $oDiv In $oDivs
    If String(_IEPropertyGet($oDiv, "InnerText")) = $sSearch Then
        _IEAction($oDiv, "click")
        _IELoadWait($oIE)
        ExitLoop
    EndIf
Next

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

What is the website?

It's a site you have to log in to, so you won't be able to get to it.

I've made a small change to big_daddy's code (adding a String function).

Give it a try and see if it doesn't work for you...

Dale

#include <IE.au3>

$sURL = "somewhere.com"
$sSearch = "Text Link"

$oIE = _IECreate($sURL)
$oFrame = _IEFrameGetObjByName($oIE, "options")
$oDivs = _IETagNameGetCollection($oFrame, "DIV")
For $oDiv In $oDivs
    If String(_IEPropertyGet($oDiv, "InnerText")) = $sSearch Then
        _IEAction($oDiv, "click")
        _IELoadWait($oIE)
        ExitLoop
    EndIf
Next
ok, so I tried your string thing... it did work... THANK YOU !!

Bre

Edited by BreCalmor
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...