Jump to content

Finding text in firefox and clicking on it if its a hyperlink?


Recommended Posts

Hey guys, I'm trying to make a program that will interact with mozilla firefox.

I already have it start firefox using this code,

Run("C:\Program Files\Mozilla Firefox\firefox.exe")
WinWaitActive("Speed Dial - Mozilla Firefox")

It then goes to the webpage using this code

MouseClick("left", 329, 93, 1)
Send("type webpage url")
Send("{ENTER}")
WinWaitActive("waiting for webpage url")

This is where my first question is, is there any way to get firefox to start on a certain webpage?

Or is there a way to get it to go to a webpage without having to select the url bar, type the text in manually and the press enter?

Here is where I really need help though.

Once on the webpage I need it to search for certain text.

I realize I can just have it use ctrl+f, type the text and see if the result is there or not.

HOWEVER once it has searched for that text it then needs to interact with it (this is where I get lost).

I can figure out if the text is on the page or not, that is not problem. If it is on the page though I need it to move the mouse to where that text is and click on it (since it will be a hyperlink). Realize of course that the hyperlink won't always be the same, it changes each time you visit the site.

Any help would be wonderful.

Thanks, - Derek.

Link to comment
Share on other sites

This is where my first question is, is there any way to get firefox to start on a certain webpage?

You could change your 'homepage' or maybe (shot in the dark) FireFox accepts urls as a parameter when you start it (something like "C:\Pogram Files\FireFox.exe http://www.google.com").

You might also try using a UDF automation library such as this-

http://autoit.de/index.php?page=Thread&amp...ID=362994565051

Link to comment
Share on other sites

Take a look here. The site is translated from German, but it does have what you need.

http://www.autoitscript.com/forum/index.ph...1&hl=ff.au3

I read over it, and it does seem like it would be some very useful scripting however I don't know how to get it into my autoit.

For example I got to this link and it has tab selecting and hyperlink clicking but do I just copy and paste the whole pages code into my code/file or do I need to program it into my autoit or something? (page I'm talking about: http://thorsten-willert.de/Themen/AutoIt-F.../FF.au3/FF.au3)

EDIT:

(something like "C:\Pogram Files\FireFox.exe http://www.google.com").

^That worked just fine, thank you.

Edited by SwordHunter4Ever
Link to comment
Share on other sites

Okay I found a way to make it detect where the hyperlink is, I have it highlight the located text now which changes the color.

Now though, I need to do a pixel search for that color so that it can locate and click on it..

The color is: 0x38D878

Its location should be within these cords (this is relative to my full monitor view);

X1: 395

Y1: 198

X2: 1418

Y2: 849

With that information my pixel search command line should be;

$coord = PixelSearch( 395, 198, 1418, 849, 0x38D878 )

Correct?

If that is the pixel search line that I need to locate the text, I now need it to click where it found those pixels. However I only want it to click on the first instance of the pixel (thus only the first pixel on the screen scanning from left to right then top to bottom (I'm assuming thats how it scans) will be clicked on).

I understand that the code should be similar to the following, however I don't know what to put in where the ?'s are.

Do
    $coord = PixelSearch( 486, 864, 486, 864, 0x1a1a1a )
If @error Then
  ; ???Jump back up to a previous step/line and redo it, I don't know the command for that I can either figure it out later or one of you can tell me how to do it.
EndIf
    $coord = PixelSearch( 486, 864, 486, 864, 0x1a1a1a ); do I need to repeat this?
If Not @error Then
; ???I need to know what goes here so that ti will click on the first instance of the located pixel with the left mouse click.
EndIf
EndFunc

Any help would be great, thanks guys =]

Edited by SwordHunter4Ever
Link to comment
Share on other sites

If you want to use the FF.au3, just copy the FF.au3 into your AutoIt/Include-Directory and install the FF-AddOn MozLab, then you can search and click - e.g.:

#include <FF.au3>

$Socket = _FFStart("http://www.yoursite.net")
If $Socket > -1 Then _FFClickLink($Socket,"TextToSearch","text")
Edited by Stilgar
Link to comment
Share on other sites

If you want to use the FF.au3, just copy the FF.au3 into your AutoIt/Include-Directory and install the FF-AddOn MozLab, then you can search and click - e.g.:

#include <FF.au3>

$Socket = _FFStart("http://www.yoursite.net")
If $Socket > -1 Then _FFClickLink($Socket,"TextToSearch","text")
Well that looks like a nice script.

Could you give me the exact link where I get teh FF.au3 to put into my AutoIt/Include-Directory?

and sorta tell me where to find the AutoIt/Include-Directory?

I've never actually done anything with that before.

Link to comment
Share on other sites

As .au3

What am I doing wrong?

HotkeySet("{HOME}","_end")
Func _end()
Exit 0
EndFunc
WinMinimizeAll()

WinActivate("America - Google Search - Mozilla Firefox", "")
WinWaitActive("America - Google Search - Mozilla Firefox")
Sleep(500); active - firefox

#include <FF.au3>
$Socket = _FFStart("http://www.google.com/search?hl=en&q=America&btnG=Google+Search")
If $Socket > -1 Then _FFClickLink($Socket,"United States - Wikipedia, the free encyclopedia","text")
    
Exit

Okay so basically I already have firefox started and I want it to switch to that window which it does.

The _FFStart command trys to create a new window though, so I want that gone.

However if I remove that I don't think it will click the link because the $socket no longer has a value above -1.

So where do I place "#include <FF.au3> do I put that before everything?

What is the basic command to make it search for a link and then click on it? (The text on screen, not the url code).

Link to comment
Share on other sites

If you have FireFox and MozLab already started you can use two variations:

$Socket = _FFConnect()

or

$Socket = _FFStart($Socket, URL, Default, 2)

to create a connection to FireFox.

The basic command to click on a link-text is:

_FFClickLink($Socket,"TheTextToCklick","text")

the argument "text" searches for the text. The text to search must not be the full text it can be a substring, too.

The FF.au3-docs are here (sorry translation is not ready)

The best place for #include ... statements is the start of the script.

Edited by Stilgar
Link to comment
Share on other sites

If you have FireFox and MozLab already started you can use two variations:

$Socket = _FFConnect()

or

$Socket = _FFStart($Socket, URL, Default, 2)

to create a connection to FireFox.

The basic command to click on a link-text is:

_FFClickLink($Socket,"TheTextToCklick","text")

the argument "text" searches for the text. The text to search must not be the full text it can be a substring, too.

The FF.au3-docs are here (sorry translation is not ready)

The best place for #include ... statements is the start of the script.

You are a savior =]

I'm gonna go mess around with it a bit, I'll let you know what my results are.

Link to comment
Share on other sites

If you have FireFox and MozLab already started you can use two variations:

$Socket = _FFConnect()

or

$Socket = _FFStart($Socket, URL, Default, 2)

to create a connection to FireFox.

The basic command to click on a link-text is:

_FFClickLink($Socket,"TheTextToCklick","text")

the argument "text" searches for the text. The text to search must not be the full text it can be a substring, too.

The FF.au3-docs are here (sorry translation is not ready)

The best place for #include ... statements is the start of the script.

I can't get this to work at all :P

I have the Mozlab thing running on startup and everything.

I have the FF.au3 file saved as you told me to.

However this is my script and I keep getting variable undefined errors.

#include <FF.au3>

$Socket = _FFStart($Socket, "http://www.google.com/search?hl=en&q=America&btnG=Google+Search", Default, 2)
sleep(2500)
_FFClickLink($Socket,"United States - Wikipedia","text")
Link to comment
Share on other sites

Sorry my fault :P

$Socket = _FFStart("URL", Default, 2)

#include <FF.au3>

$Socket = _FFStart("http://www.google.com/search?hl=en&q=America&btnG=Google+Search", Default, 2)
_FFClickLink($Socket,"United States - Wikipedia","text")

The _FFStart - function returns if the page is complete loaded so you don't have to use "sleep" after _FFStart.

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