Jump to content
Macro Express Forums

Finding a word on page, executing commands depending on results


camaro92

Recommended Posts

How would I be able to search for a word (Example: "hello") on a page and IF the word "HELLO" exists then do something, and if it does NOT exist then do another instead.

 

I can easily execute a FIND command in the browser to look for a word but that's it.. How would I incorporate that into the script so the script can tell whether that FIND command resulted in a RESULT or NOT FOUND RESULT..??

 

Or is there an easier way of doing it rather than using the browser FIND technique?

 

Thanks

Link to comment
Share on other sites

When you do the FIND, does it highlight the found word? If so, then this may work: copy the highlighted word into the clipboard and check clipboard contents like this:

 

CLIPBOARD EMPTY command (sets clipboard content to null)

FIND word

CLIPBOARD COPY command

IF CLIPBOARD TEXT = "searched-for word"

DO WHATEVER

END IF

IF CLIPBOARD = "" (nulls)

DO WHATEVER (word not found, so copy-to-clipboard does not put anything into the clipboard)

ENDIF

Link to comment
Share on other sites

Interesting challenge! The following seems to work OK. Note that it is exact. For example, using a target of 'technique' it reported a hit, while ''techniques' did not.

 

The key idea was to test the colour of the Find box. The exact pixel position of the point to click in that box will depend on your screen resolution, so find that with the Mouse Locator and change that command accordingly.

 

// Firefox - Prompted search-camaro92

// Allow user to enter required string

Variable Set String %T1% from Prompt

// Activate FF if not already uppermost

If Not Window Title "Mozilla Firefox" on top

Activate Window: "Mozilla Firefox"

End If

// Open the FF Find box and paste in the target

Text Type: <CONTROL>f

Delay 100 Milliseconds

Text Type: %T1%

Delay 100 Milliseconds

// Test the colour of the Find box

Mouse Move Window 184, 1081

Get Pixel: Under Mouse into %N1%

// If colour is WHITE (16777215) then there is a hit.

If Variable %N1% = 16777215

Text Box Display: Result

Delay 100 Milliseconds

Else

Text Box Display: Result

Delay 100 Milliseconds

End If

Macro Return

 

<REM2:Firefox - Prompted search-camaro92><REM2:Allow user to enter required string><TVAR2:01:02:FEnter your search targetTFCenter:Center><REM2:Activate FF if not already uppermost><IFOTH:11:2:Mozilla Firefox><ACTIVATE2:Mozilla Firefox><ENDIF><REM2:Open the FF Find box and paste in the target><TEXTTYPE:<CONTROL>f><MSD:100><TEXTTYPE:%T1%><MSD:100><REM2:Test the colour of the Find box><MMW2:184,1081><GETPXM:1><REM2:If colour is WHITE (16777215) then there is a hit.><IFVAR2:2:01:1:16777215><TBOX4:T:4:CenterCenter000278000200:000:ResultThe word %T1% has been found and is highlighted by Firefox on this page.><MSD:100><ELSE><TBOX4:T:4:CenterCenter000278000200:000:ResultThe string %T1% has NOT been found, as you can tell by the red shading of the Find box.><MSD:100><ENDIF><MRETURN>

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Forget the Find command from your browser. It's way easier than that.

 

Variable Set String %T1% from Prompt
Text Type: <CONTROL>a
Clipboard Copy
Variable Set String %T2% from Clipboard
If Variable %T2% contains variable %T1%
 Text Box Display: Peform "Yes" function
Else
 Text Box Display: Peform "No" function
End If

 

<TVAR2:01:02:FWhat Word are you looking for?FFCenter:Center><TEXTTYPE:<CONTROL>a><CLIPC><TVAR2:02:03:><IFVAR2:4:02:7:T1><TBOX4:T:1:CenterCenter000278000200:000:Peform "Yes" functionThis box represents what will happen if the search-for word exists.><ELSE><TBOX4:T:1:CenterCenter000278000200:000:Peform "No" functionThis box represents what will happen if the search-for word does not exists.><ENDIF>

 

Admittedly, I am in a hurry, so may have missed something in the above posts, but I do similar functions all the time (assuming I understood

correctly), and this is how I do them.

 

-EDIT (1hr later)

I've had a minute to look over the original question and the other replies, and I'm still confident that my example should work fine for what you

are trying to do. Keep in mind that you may need to add delays between the CTRL+A function and the Clipboard Copy command. You might

also want to consider adding a Mouse Move command to a position relative to the window you're going to copy and a Left Click command to

ensure the CTRL+A highlights the correct area of the window (I have had trouble with Ctrl+a and tables in web-sites before), but probably won't

need it.

Link to comment
Share on other sites

Works perfectly here Steve - and a lot neater than my roundabout method!

 

Oddly, so far I haven't got it working in ME Pro. Here's my code.

Variable Set String %T[1]%: Prompt

Text Type (Simulate Keystrokes): <CONTROL>a

Delay: 100 milliseconds

Clipboard Copy

Delay: 100 milliseconds

Variable Set String %T[2]% from the clipboard contents

If Variable %T[2]% Contains "%T[1]%"

Text Box Display: Peform "Yes" function

Else

Text Box Display: Peform "No" function

End If

Macro Return

 

<VARIABLE SET STRING Option="\x01" Destination="%T[1]%" Prompt="What Word are you looking for?" Mask="FALSE" OnTop="TRUE" Left="Center" Top="Center" Monitor="0"/>
<TEXT TYPE Action="0" Text="<CONTROL>a"/>
<DELAY Flags="\x02" Time="100"/>
<CLIPBOARD COPY/>
<DELAY Flags="\x02" Time="100"/>
<VARIABLE SET STRING Option="\x02" Destination="%T[2]%"/>
<IF VARIABLE Variable="%T[2]%" Condition="\x06" Value="%T[1]%" IgnoreCase="FALSE"/>
<TEXT BOX DISPLAY Title="Peform \"Yes\" function" Content="{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang2057\\f0\\fs16 This box represents what will happen if the search-for word exists.\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<ELSE/>
<TEXT BOX DISPLAY Title="Peform \"No\" function" Content="{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang2057\\f0\\fs16 This box represents what will happen if the search-for word does not exists.\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<END IF/>
<MACRO RETURN/>

 

Neither message appeared. Just finished with all text selected in FF. And, although there were no error messages when saving the macro, after it ran I saw "Line 7: Debug Error: Undefined variable or the variable is the wrong type"

 

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Works perfectly here Steve - and a lot neater than my roundabout method!

 

Oddly, so far I haven't got it working in ME Pro. Here's my code.

 

 

 

--

Terry, East Grinstead, UK

Hey Terry,

 

I just now got a chance to look into my macro and experiment with why it isn't working in ME Pro. My first thought

was that it was a timing issue; and, in fact, it was - at least initially. ME Pro is so fast that it tried to find the required

text before my computer had been able to complete the Clipboard Copy. So I incorporated a pair of .5 second

delays (I always start with a big delay and then work my way down).

 

On the very first run with the delay I got an error. I will be bug-reporting it in a few minutes. The error says:

 

Script Error

Date: 1/14/2009 1:55:30 PM

The following error was encountered:

Undefined variable or the variable is the wrong type

"%T1%"

Macro Name: Find Word

Line Number: 7

 

Line 7 is:

If Variable %T[2]% Contains "%T[1]%"

 

Here is the macro as it stands:

<VARIABLE SET STRING Option="\x01" Destination="%T[1]%" Prompt="What Word are you looking for?" Mask="FALSE" OnTop="FALSE" Left="Center" Top="Center" Monitor="0"/>
<TEXT TYPE Action="0" Text="<CONTROL>a"/>
<DELAY Flags="\x01" Time=".5"/>
<CLIPBOARD COPY/>
<DELAY Flags="\x01" Time=".5"/>
<VARIABLE SET STRING Option="\x02" Destination="%T[2]%"/>
<IF VARIABLE Variable="%T[2]%" Condition="\x06" Value="%T[1]%" IgnoreCase="FALSE"/>
<TEXT BOX DISPLAY Title="Peform \"Yes\" function" Content="This box represents what will happen if the search-for word exists." Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<ELSE/>
<TEXT BOX DISPLAY Title="Peform \"No\" function" Content="This box represents what will happen if the search-for word does not exists." Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<END IF/>

 

There is nothing different about this macro and its ME 3.x counterpart, other than the delays.

 

This was a straight up Copy/Paste from the Editor in ME 3 to the Editor in ME Pro.

 

I'm going to toy with the script and see if changing the variable names fixes it, but I don't see why it would make

a difference.

 

If it matters, I was searching for the word "Mouse" on this very thread. Worked fine with ME 3, erred with ME Pro.

Link to comment
Share on other sites

Steve,

 

That error about variable type is exactly what I was getting earlier. Yet as you probably saw from my subsequent reply to Stan, a repeat run of the same macro a few hours later did not give the error. This sort of inconsistent behaviour is why I feel that ME 3 Pro is still flakey in the variables area, but without being able to pin it down.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Terry and Steve -

 

I have used the <CTRL>a technique with Internet Explorer, never with Firefox. On some IE screens I found it is necessary to click once with the mouse, somewhere inside the window, before doing the <CTRL>a. Without the click, nothing gets highlighted and therefore nothing is copied to the clipboard. Depending how the browser screen was built, it might be necessary to click in different areas, say near the top as opposed to the middle, etc.

Link to comment
Share on other sites

Terry and Steve -

 

I have used the <CTRL>a technique with Internet Explorer, never with Firefox. On some IE screens I found it is necessary to click once with the mouse, somewhere inside the window, before doing the <CTRL>a. Without the click, nothing gets highlighted and therefore nothing is copied to the clipboard. Depending how the browser screen was built, it might be necessary to click in different areas, say near the top as opposed to the middle, etc.

Hi Bob,

 

I hadn't been using Firefox for this macro (even if I had, the macro should still work, though). However, after your

post, I felt it best to give other browsers a try. I have duplicated the error in IE, Google Chrome, Firefox, and

Opera.

 

I am clicking in the window before running the macro, and the Ctrl+a is highlighting the entire page. The error is

occurring because the macro is not recognizing Text variable %T[1]% which is just silly.

 

I'm going to copy this thread in the Macro Express Pro forum as I think it has grown beyond the scope of ME 3.x

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...