Jump to content
Sign in to follow this  
mjoly

[solved] Select.. and click?

Recommended Posts

mjoly

Hello!

i'm just started using AutoIt last week, and i try to discover some of the functionnalities of it.

But i have a problem:

a link coded with

<a onclick="execute('connexionsList');">Connexions</a><br>

is not a "real" html link that is not accessible in Firefox with "tab" and can be open with "enter"..

You can search for it with an ctrl+f, il appears selected, but you can't "enter" this kind of link.

Is someone nows how to deal with it ?? I really need to "click" on this word ! (maybe in sending the html par of code.. i don't know!!))

Please help !! :D

Edited by mjoly

Share this post


Link to post
Share on other sites
DaRam

The web page is possibly using a javascript function called execute which is why you cannot click on it.

Look at the full html source of the page to locate the javascript, if not found look for an external .js that contains the javascript (similar to an Autoscript #include).

Example: <script src="myscripts.js>

Share this post


Link to post
Share on other sites
mjoly

The web page is possibly using a javascript function called execute which is why you cannot click on it.

Look at the full html source of the page to locate the javascript, if not found look for an external .js that contains the javascript (similar to an Autoscript #include).

Example: <script src="myscripts.js>

In fact, it is..

<script language="Javascript" src="execute.js"></script>

The problem is: Is it possible to done something with that ?

Share this post


Link to post
Share on other sites
PsaltyDS

Hello!

i'm just started using AutoIt last week, and i try to discover some of the functionnalities of it.

But i have a problem:

a link coded with

<a onclick="execute('connexionsList');">Connexions</a><br>

is not a "real" html link that is not accessible in Firefox with "tab" and can be open with "enter"..

You can search for it with an ctrl+f, il appears selected, but you can't "enter" this kind of link.

Is someone nows how to deal with it ?? I really need to "click" on this word ! (maybe in sending the html par of code.. i don't know!!))

Please help !! :D

I think it is still a link, even though it doesn't have an href attribute. So this might work:
#include <IE.au3> 

; ...

$colLinks = _IELinkGetCollection($oIE)
For $oLink in $colLinks
    If String($oLink.innerText) = "Connexions" Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
Next

The <a> tag means "anchor", and href is just an attribute of that <a> tag. If the html you have doesn't come up in the "links" collection, then you might have to use this instead:

$colLinks = _IETagNameGetCollection($oIE, "a")

I don't have a convenient page to test that on.

:D

Edit: I was really curious if an <a> tag without href would be a "link", and the answer is no. This demo proves it and also shows the idea of using _IETagNameGetCollection() works for this:

#include <IE.au3>

; HTML for test page:
Global $s_html = "<HEAD>" & @CR
$s_html &= "<TITLE>_IE_Example('basic')</TITLE>" & @CR
$s_html &= "<STYLE>body {font-family: Arial}</STYLE>" & @CR
$s_html &= "</HEAD>" & @CR

$s_html &= '<script type="text/javascript" language="javascript">' & @CR
$s_html &= 'function TestMe()' & @CR
$s_html &= '{' & @CR
$s_html &= 'alert("Hello, world!");' & @CR
$s_html &= '}' & @CR
$s_html &= '</script>' & @CR

$s_html &= "<BODY>" & @CR
$s_html &= '<a onclick="java script:TestMe();")>Connexions</a>' & @CR
$s_html &= "</HTML>"

; Open in IE
Global $oIE = _IECreate()
_IEDocWriteHTML($oIE, $s_html)

; Get links
Global $colLinks = _IELinkGetCollection($oIE)
Global $iLinkCnt = @extended
If $iLinkCnt Then
    MsgBox(64, "Links", "There were " & $iLinkCnt & " links.")
    For $oLink in $colLinks
        If String($oLink.innertext) = "Connexions" Then
            _IEAction($oLink, "click")
            ExitLoop
        EndIf
    Next
Else
    MsgBox(16, "No Links", "There were no links")
    ; Try it with <a> tags
    $colLinks = _IETagNameGetCollection($oIE, "a")
    $iLinkCnt = @extended
    MsgBox(64, "Tags", "There were " & $iLinkCnt & " tags." & @LF)
    For $oLink in $colLinks
        If String($oLink.innertext) = "Connexions" Then
            _IEAction($oLink, "click")
            ExitLoop
        EndIf
    Next
EndIf

:o

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
mjoly

Thanks for this.. but just one little thing: i'm gona use this with.. Firefox, not IE.. so i'm almost sure that this can be adaptable with the FF.au3 UDF.. but i'm just too new with AutoIT for that...

I think it is still a link, even though it doesn't have an href attribute. So this might work:

#include <IE.au3> 

; ...

$colLinks = _IELinkGetCollection($oIE)
For $oLink in $colLinks
    If String($oLink.innerText) = "Connexions" Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
Next

The <a> tag means "anchor", and href is just an attribute of that <a> tag. If the html you have doesn't come up in the "links" collection, then you might have to use this instead:

$colLinks = _IETagNameGetCollection($oIE, "a")

I don't have a convenient page to test that on.

:D

Edit: I was really curious if an <a> tag without href would be a "link", and the answer is no. This demo proves it and also shows the idea of using _IETagNameGetCollection() works for this:

#include <IE.au3>

; HTML for test page:
Global $s_html = "<HEAD>" & @CR
$s_html &= "<TITLE>_IE_Example('basic')</TITLE>" & @CR
$s_html &= "<STYLE>body {font-family: Arial}</STYLE>" & @CR
$s_html &= "</HEAD>" & @CR

$s_html &= '<script type="text/javascript" language="javascript">' & @CR
$s_html &= 'function TestMe()' & @CR
$s_html &= '{' & @CR
$s_html &= 'alert("Hello, world!");' & @CR
$s_html &= '}' & @CR
$s_html &= '</script>' & @CR

$s_html &= "<BODY>" & @CR
$s_html &= '<a onclick="java script:TestMe();")>Connexions</a>' & @CR
$s_html &= "</HTML>"

; Open in IE
Global $oIE = _IECreate()
_IEDocWriteHTML($oIE, $s_html)

; Get links
Global $colLinks = _IELinkGetCollection($oIE)
Global $iLinkCnt = @extended
If $iLinkCnt Then
    MsgBox(64, "Links", "There were " & $iLinkCnt & " links.")
    For $oLink in $colLinks
        If String($oLink.innertext) = "Connexions" Then
            _IEAction($oLink, "click")
            ExitLoop
        EndIf
    Next
Else
    MsgBox(16, "No Links", "There were no links")
; Try it with <a> tags
    $colLinks = _IETagNameGetCollection($oIE, "a")
    $iLinkCnt = @extended
    MsgBox(64, "Tags", "There were " & $iLinkCnt & " tags." & @LF)
    For $oLink in $colLinks
        If String($oLink.innertext) = "Connexions" Then
            _IEAction($oLink, "click")
            ExitLoop
        EndIf
    Next
EndIf

:o

Share this post


Link to post
Share on other sites
Stilgar

Hello,

that's not a real <a ....> tag ... , so _FFClickLink wouldn't work there.

But for FireFox use the latest version of the FF.au3 and try this:

#include <FF.au3>

If _FFConnect() Then

; version 1 / more flexible
  _FFXPath("//a[position()=1 and contains(.,'Connexions')]","",9)
  _FFClick("FFau3.xpath")
; version 2 / or simple
  _FFClick('a','tag', 0)

EndIf

Share this post


Link to post
Share on other sites
mjoly

Hello,

that's not a real <a ....> tag ... , so _FFClickLink wouldn't work there.

But for FireFox use the latest version of the FF.au3 and try this:

#include <FF.au3>

If _FFConnect() Then

; version 1 / more flexible
  _FFXPath("//a[position()=1 and contains(.,'Connexions')]","",9)
  _FFClick("FFau3.xpath")
; version 2 / or simple
  _FFClick('a','tag', 0)

EndIf
The problem is that, if i understand, i do need to use MozRepl, but as i seen on the mozilla addons website, this application is not working with FF 3.xx.. or is it possible?

Share this post


Link to post
Share on other sites
Stilgar

The problem is that, if i understand, i do need to use MozRepl, but as i seen on the mozilla addons website, this application is not working with FF 3.xx.. or is it possible?

Yes you need MozRepl and it's compatible with FF 3.x:

MozRepl

Share this post


Link to post
Share on other sites
mjoly

Yes you need MozRepl and it's compatible with FF 3.x:

MozRepl

I've finally found the mozrpl exactly on the site you give the link, but there's no reaction from FF with the code..

WinActivate("Firefox")
WinSetOnTop("Firefox", "", 1)


If _FFConnect() Then
; version 1 / more flexible
  _FFXPath("//a[position()=1 and contains(.,'Connexions')]","",9)
  _FFClick("FFau3.xpath")
; version 2 / or simple
;  _FFClick('a','tag', 0)
EndIf

Did i have something to do to be sure that both MozRepl is working (more than only the "deactivate" case on the firefox plugins nor the script itself ???

Share this post


Link to post
Share on other sites
Stilgar

I've finally found the mozrpl exactly on the site you give the link, but there's no reaction from FF with the code..

WinActivate("Firefox")
WinSetOnTop("Firefox", "", 1)


If _FFConnect() Then
; version 1 / more flexible
  _FFXPath("//a[position()=1 and contains(.,'Connexions')]","",9)
  _FFClick("FFau3.xpath")
; version 2 / or simple
;  _FFClick('a','tag', 0)
EndIf

Did i have something to do to be sure that both MozRepl is working (more than only the "deactivate" case on the firefox plugins nor the script itself ???

If you have it installed the you must start it in the menu Extras / MozRepl / Start.

If you use _FFStart then it is always activatet, or you choose "Activate on startup" in the extras menu.

Share this post


Link to post
Share on other sites
mjoly

If you have it installed the you must start it in the menu Extras / MozRepl / Start.

If you use _FFStart then it is always activatet, or you choose "Activate on startup" in the extras menu.

It's done with MozRepl.. but nothing happens. No reaction, and the script is ending normaly, but i have no reaction from the tab/window (i've tested with both.. multiples tab / one window alone).

How can i be sure that the script is searching for the string? something with _FFXPath to tell that the characters are found for example..

Share this post


Link to post
Share on other sites
Stilgar

It's done with MozRepl.. but nothing happens. No reaction, and the script is ending normaly, but i have no reaction from the tab/window (i've tested with both.. multiples tab / one window alone).

How can i be sure that the script is searching for the string? something with _FFXPath to tell that the characters are found for example..

You can see it in the output/console from your editor if _FFXPath doesn't find anything.

The query "//a[position()=1" searches "Connexions" only find the first link.

You can try:

_FFXPath("//a[contains(.,'Connexions')]","",9)

to search in all links.

Share this post


Link to post
Share on other sites
mjoly

You can see it in the output/console from your editor if _FFXPath doesn't find anything.

The query "//a[position()=1" searches "Connexions" only find the first link.

You can try:

_FFXPath("//a[contains(.,'Connexions')]","",9)

to search in all links.

You've done such a great job all of you!!

It works!

Thanks a lot, that's really great!!

Share this post


Link to post
Share on other sites
mjoly

Hi Stilgar.

After the solution you gave me, which is working in most cases, a problem appears: sometimes, i have another windows appearing before this page (a choice between 2 check cases), but it's not really easy (in the way i understand the loop if.. then.. else) to check 2 conditions like the first you solve:

i mean, the new message appearing have the word "migration" , and i have to check it before it passes the script to the other part with the detection of "connexions":

If _FFConnect() Then
      _FFXPath("//a[contains(.,'Connexions')]","",9)
      _FFClick("FFau3.xpath")
EndIf

I've tried to test with the loop only with _FFXPath If _FFXPath etc.. then _FFClick... else.. but it's not working..

Simply =)> page appears with "migration" then quit the loop (no need to check the "Connexions"), if no "migration, then click on "Connexions"..

Do you have any simple idea about this ?

Share this post


Link to post
Share on other sites
Stilgar

Hi mjoly,

do you mean something like this?

If _FFConnect() Then
    Do
        Sleep(1000)
    Until _FFSearch("migration")
    ; or if you would better locate the word:
    ; _FFXPath(".","migration",11) ; 11 = contains

    _FFClick( _FFXPath("//a[contains(.,'Connexions')]","",9) )
EndIf

Share this post


Link to post
Share on other sites
mjoly

Hi mjoly,

do you mean something like this?

If _FFConnect() Then
    Do
        Sleep(1000)
    Until _FFSearch("migration")
    ; or if you would better locate the word:
    ; _FFXPath(".","migration",11) ; 11 = contains

    _FFClick( _FFXPath("//a[contains(.,'Connexions')]","",9) )
EndIf
Not exactly.. the problem is that if it founds "migration", then the script has to end, nor no "migration" then point and click on "Connexions"..

At this moment, it continues, even when it founds "migration"..

Share this post


Link to post
Share on other sites
Stilgar

Not exactly.. the problem is that if it founds "migration", then the script has to end, nor no "migration" then point and click on "Connexions"..

At this moment, it continues, even when it founds "migration"..

This one?

If _FFConnect() Then
    While True
        If _FFSearch("migration") Then
            ExitLoop
        Else
            _FFClick( _FFXPath("//a[contains(.,'Connexions')]", "", 9))
            ExitLoop
        EndIf
        Sleep(1000)
    Wend
EndIf

Share this post


Link to post
Share on other sites
PsaltyDS

This one?

If _FFConnect() Then
    While True
        If _FFSearch("migration") Then
            ExitLoop
        Else
            _FFClick( _FFXPath("//a[contains(.,'Connexions')]", "", 9))
            ExitLoop
        EndIf
        Sleep(1000)
    Wend
EndIf
The While/WEnd is not looping because there is an ExitLoop in both cases of the If/Else/EndIf. Regardless of how _FFSearch() returns, the loop exits.

^_^


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Stilgar

The While/WEnd is not looping because there is an ExitLoop in both cases of the If/Else/EndIf. Regardless of how _FFSearch() returns, the loop exits.

;)

Ops ^_^

While True
    If _FFSearch("migration") Then
        ExitLoop
    Else
        If _FFClick( _FFXPath("//a[contains(.,'Connexions')]", "", 9)) Then ExitLoop
    EndIf
    Sleep(1000)
Wend

Share this post


Link to post
Share on other sites
mjoly

This one?

If _FFConnect() Then
    While True
        If _FFSearch("migration") Then
            ExitLoop
        Else
            _FFClick( _FFXPath("//a[contains(.,'Connexions')]", "", 9))
            ExitLoop
        EndIf
        Sleep(1000)
    Wend
EndIf
Thanks again.. for both stligar / PsaltyDS

I've slightly have to modify the script (exit instead of ExitLoop) and it's OK!!

If _FFConnect() Then
    While True
        If _FFSearch("migration") Then
            WinActivate("Firefox")
            WinSetOnTop("Firefox", "", 0)
            Exit
        Else
            _FFClick( _FFXPath("//a[contains(.,'Connexions')]", "", 9))
            ExitLoop
        EndIf
        Sleep(1000)
    Wend
EndIf

I think it take few hours for me too find that !!!

Great job!

Edited by mjoly

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.