getting text location

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

cyberiguana
Newbie
Posts: 13
Joined: Tue May 18, 2010 6:54 pm

getting text location

Post by cyberiguana » Tue May 18, 2010 6:59 pm

hello,
I want to search a word that appears multiple times on the screen,
get the matches as in regex plus the coordinates of each match.
for example if the drawing is a text and I look the word "X" I want to get the number 4 and the cordinates of each "X":

------------X----------
--X--------------------
--------X--------------
------------------------
-----------------------
-----------------------
-----------------X----

is this possible?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

find text on screen

Post by adroege » Tue May 18, 2010 7:22 pm

Image recognition should be able to do it.

Also, what type of on-screen control is the text in? It's possible that GetControlText> can also read the text directly out of the control faster and with less chance of error.

Another technique I have used before is to (using keyboard commands) highlight the text and send it to the clipboard (using ctrl-c) and then retrieve the text from the clipboard into a variable and search it that way.


So you see there are many possibilities.

cyberiguana
Newbie
Posts: 13
Joined: Tue May 18, 2010 6:54 pm

Post by cyberiguana » Wed May 19, 2010 5:39 am

what would be the easiest way?
the text is a simple text in a webpage, not a button or something, however its frequency and location changes.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

image recognition

Post by adroege » Wed May 19, 2010 11:09 am

what would be the easiest way?
This still depends upon what you are going to do once you find the text. Now that I hear it is a webpage you have yet another way. You can simply retrieve the entire webpage using HTTPRequest> command and parse the returned HTML using RegEx> (regular expressions).

Is this text in a hyperlink? Why do you want to know the screen coordinates? This could change depending upon the width/height of the browser window, etc. If you want to "click on the hyperlink" you don't need to know the screen coordinates, because you can do a "virtual click" by using the DOM (Document object model) and the browser using VBScript.

Not knowing the full details of what you want to do I would say you should start using image recognition. Read the help if you need to, then start putting together code and testing it. If you run into trouble, post the code you have written, as it's much easier to help when there is some code to look at instead of vague ideas.

Enjoy!

cyberiguana
Newbie
Posts: 13
Joined: Tue May 18, 2010 6:54 pm

Post by cyberiguana » Wed May 19, 2010 12:00 pm

well I've managed to solve the issue with image recognition, I only have 1 problem.
I use findimagepos which then creates an array of matching coordinates.
when I check a set of coordinates, like Xarr_1 and Yarr_1, I want to know if the next set after it, Xarr_2 and Yarr_2, have coordinates in them.
I used:
Assigned>xarr_1,result

and even though it has a number in it, I get returned FALSE in the result
why?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

FindImagePos command returns the number of matches found

Post by adroege » Wed May 19, 2010 12:28 pm

FindImagePos>bitmap_to_find,bitmap_to_scan|SCREEN,color_tolerance,return_center,X_Array,Y_Array,NumFound
In the FindImagePos> command:
NumFound returns the number of matches found.

This should let you know how many array variables
have been created.

cyberiguana
Newbie
Posts: 13
Joined: Tue May 18, 2010 6:54 pm

Post by cyberiguana » Wed May 19, 2010 2:14 pm

well my solution failed.
I captured the text as an image and scanned the screen comparing it.
the problem is that sometimes all of the results don't appear in the same screen and I need to page down the webpage and repeat the scanning in order to get all the matches.
there is sometimes only a couple of lines more to the page and not a whole screen so the macro gets almost the same screen again with the same results and finds them again, doesnt know when to stop.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed May 19, 2010 2:29 pm

Well, if scrolling the page is an issue I'd say you need to try these other
options:
"Another technique I have used before is to (using keyboard commands) highlight the text and send it to the clipboard (using ctrl-c) and then retrieve the text from the clipboard into a variable and search it that way. "
"Retrieve the entire webpage using HTTPRequest> command and parse the returned HTML using RegEx> (regular expressions). "

cyberiguana
Newbie
Posts: 13
Joined: Tue May 18, 2010 6:54 pm

Post by cyberiguana » Wed May 19, 2010 3:47 pm

I've tried copying the text to the clipboard, but it doesn't help with the scrolling issue.
Getting the entire page sounds nice, but regex won't give me the cordinates of the matches.
This is getting frustrating...

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed May 19, 2010 3:56 pm

When I do Ctrl-A on a webpage it selects ALL the text without
me having to scroll the text into view. So this should work.

With the scrolling issue, I don't understand why you want to
know the coordinates on the screen since as I move the
scroll bars the text moves and so do all the coordinates.
They aren't fixed on the screen.

If it's so you can "click" on them, there are other ways to
accomplish that.

cyberiguana
Newbie
Posts: 13
Joined: Tue May 18, 2010 6:54 pm

Post by cyberiguana » Wed May 19, 2010 5:37 pm

I'm trying to get the names of different products on a webpage.
the page is like tiles of products as you would in see in a typical webstore.
each "tile" looks like this:
///////////////
///////////////
////Picture///
///////////////
///////////////
Name of Product
Price:
Quantity:

I need to get each name seperately, because I do some processing on each name.
first I thought I'd try to recognize the pictures, but they constantly change so I tried just searching the whole page for the "Price:" because it's constant among all the tiles and then try to copy the name above it.
However this method doesn't have the ability to know which products it has already scanned (the problem I mentioned earlier), so I'm stuck.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

parse HTML with RegEx

Post by adroege » Wed May 19, 2010 6:02 pm

I think you need to parse the HTML. If you know nothing about HTML,
then you will after finishing this excercise! :D

Just to get an ideal of what you are facing, when the page is loaded
in your browser, do View->Source (If in IE... Firefox is similar)
and look at the actual HTML code. If you are lucky it is mostly
HTML without a lot of javascript functions doing stuff.

When implemented this way it is very reliable. The only way it can
break is if the author of the web page makes drastic changes to the
code. If the site is modern and uses CSS for formatting, the HTML
is even simpler, and when the author makes changes to the CSS to
change how it looks, it doesn't change the HTML.

You would use HTTPRequest> command to read in all the HTML
into a variable, and then start parsing it. RegEx is the best, but you
might be able to use Position> and MidStr> to accomplish your goal.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

sample of website parsing using HTTPRequest

Post by adroege » Wed May 19, 2010 6:45 pm

Here is a little sample I just made in 10 minutes to get you started.

[code]

Input>zip_code,Enter a zipcode to find out the current weather
Let>URL=http://www.briansutton.com/wx/weather.h ... s&#current
HTTPRequest>URL,,GET,,HTMLResponse

Let>String1=
Let>String2=

Length>String1,String1_length

Position>String1,HTMLResponse,1,StartAt
Add>StartAt,String1_length
Position>String2,HTMLResponse,StartAt,EndAt,FALSE

Let>myLen=EndAt-StartAt

MidSTr>HTMLResponse,StartAt,myLen,myWeather
MessageModal>The current weather for zipcode %zip_code% is %CRLF%%CRLF%%myWeather%

[/code]

cyberiguana
Newbie
Posts: 13
Joined: Tue May 18, 2010 6:54 pm

Post by cyberiguana » Wed May 19, 2010 7:54 pm

I don't think you fully understand my purpose.
I need to deal with each product name seperately. I first copy the name, paste it in another webpage, get a result, and the result I paste in the "Price" field. Parsing the entire HTML and using regex won't help me because I need to know the location on screen of every name, so I can paste the corresponding result of the name in its appropriate field.

I believe image recognition is the way here, but I can't find a way for the macro to "remember" which images he already scanned.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

HTTPRequest has a POST method for updating web pages also

Post by adroege » Wed May 19, 2010 8:07 pm

You never mentioned about needing to update fields
in a webpage before...


No matter, HTTPRequest> has a POST method also

This means that you possibly DO NOT need a web browser at
all to accomplish your task. You parse page 1, get the field you
are after, do another HTTPRequest to page 2, parse the result
and then POST the result to page 3 (which updates it the same
as if you had typed it in and clicked whatever button you need
to)

You should have found my example for Weather exciting :D

Now you need to study how to do a POST method to a webpage.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts