Page 2 of 2

Re: Could I find and select text in Textarea?

Posted: Mon Nov 05, 2012 4:01 pm
by Aracknid
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?

Re: Could I find and select text in Textarea?

Posted: Mon Nov 05, 2012 4:22 pm
by Ciege
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.

Re: Could I find and select text in Textarea?

Posted: Tue Nov 06, 2012 8:07 am
by artur_gadomski
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.

Re: Could I find and select text in Textarea?

Posted: Tue Nov 06, 2012 4:09 pm
by Support Team
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

Re: Could I find and select text in Textarea?

Posted: Tue Nov 06, 2012 7:08 pm
by Ciege
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);
    }
}

Re: Could I find and select text in Textarea?

Posted: Wed Nov 07, 2012 7:40 am
by artur_gadomski
@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.

Re: Could I find and select text in Textarea?

Posted: Wed Nov 07, 2012 3:06 pm
by Aracknid
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.

Re: Could I find and select text in Textarea?

Posted: Thu Nov 08, 2012 11:50 am
by Support Team
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)