Could I find and select text in Textarea?

Ask general questions here.
User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Could I find and select text in Textarea?

Post by Aracknid » Mon Nov 05, 2012 4:01 pm

So is it possible to get the coordinates of the text we want to click on by doing some sort of pixel based calculation on the text width and height, relative to the top left corner of the HTML text area control?

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Could I find and select text in Textarea?

Post by Ciege » Mon Nov 05, 2012 4:22 pm

Sure you could figure it out... You need to do some trial and error with your code to determine properly how to find the size of the text area, the size of the text and each character, then do your math to determine where it is you want to click.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Could I find and select text in Textarea?

Post by artur_gadomski » Tue Nov 06, 2012 8:07 am

If I can hijack this thread I'd like Support to look at my snapshot. (If i can't feel free to move this post.)
I have almost the exact same scenario. Text control with some of the text being links. I'd like to be able to know where to click. For me it's a windows application in WinForms I think.

'Sorry, the board attachment quota has been reached'. I'll try to send snapshot to email.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Could I find and select text in Textarea?

Post by Support Team » Tue Nov 06, 2012 4:09 pm

Hi,

Did you already tried the things Ciege and I mentioned?
As Ciege mentioned you could click on a specific location or as I mentioned you could also try it with a image based click. Here is a link to the location dependent click method: Click Method (location).
If you check the Text attribute of the Text adapter you will also see which Word or Phrase is a link, because they are marked as "Text#LinkId=X", this could help you to locate the links.

Regards,
Markus

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Could I find and select text in Textarea?

Post by Ciege » Tue Nov 06, 2012 7:08 pm

Here is some real quick and dirty code that will find a textarea, determine it's size, determine the size of a character based on some font information, then move the cursor to each character.

This was REALLY quickly done and not perfect but should give you an idea on one way you can proceed. There is no warranty (implied or otherwise) that this will do what you need, but should get you on your way.

Code: Select all

Mouse.DefaultMoveTime = 100;
System.Diagnostics.Process.Start("iexplore.exe", "http://www.w3schools.com/tags/showit.asp?filename=tryhtml_textarea");  
Ranorex.WebDocument FooDom = "/dom[@caption='Showit v1.4']"; 
FooDom.EnsureVisible();
Ranorex.TextAreaTag FooTextArea = FooDom.FindSingle(@".//textarea", 10000);

Font MyFont = new Font("Courier", 4);
Size charSize = TextRenderer.MeasureText("A", MyFont);

int intCols = int.Parse(FooTextArea.Cols);
int intRows = int.Parse(FooTextArea.Rows);

int intX = (FooTextArea.ScreenRectangle.X);
int intY = (FooTextArea.ScreenRectangle.Y);
int intHeight = (FooTextArea.ScreenRectangle.Height);

Mouse.MoveTo(intX, intY);
Thread.Sleep(1000);

for (int r = 1; r < intRows; r++)
{
    int TempY = intY + ((intHeight / intRows * r) - (charSize.Height/ 2));
    for (int c = 0; c < intCols; c++)
    {
        int TempX = intX + (c * charSize.Width);

        Mouse.MoveTo(TempX, TempY);
        Thread.Sleep(100);
    }
}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Could I find and select text in Textarea?

Post by artur_gadomski » Wed Nov 07, 2012 7:40 am

@Markus:
We have used coordinate based approach in one case where we use this control. We did not try image based comparison (last time we tried it somewhere else it didn't seem to work and so we don't have much experience with that). Both solutions work only in certain situations so we were looking for some more general solution. We have not tried implementing Ciege's idea yet.

@Ciege:
Thx for the sample.

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Could I find and select text in Textarea?

Post by Aracknid » Wed Nov 07, 2012 3:06 pm

As a suggestion for a feature, how about this...

It's easy enough to find the text in a control and select the text, or position the I-beam in the control in a place that you want. If there was a function to "Move the pointer to the selected text" or "Move the pointer to the I-Beam" that would certainly help.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Could I find and select text in Textarea?

Post by Support Team » Thu Nov 08, 2012 11:50 am

Hello,

Thanks for your request.
We will discuss your feature request internally if we implement this in one of our next versions.

Regards,
Markus (T)