How to touch HTML controls and read its data

Class library usage, coding and language questions.
automator67
Posts: 3
Joined: Sat Aug 12, 2006 11:31 am
Location: SWITZERLAND
Contact:

How to touch HTML controls and read its data

Post by automator67 » Mon Aug 14, 2006 9:25 pm

Now that I am getting more and more curious about Ranorex I wonder whether you have a sample demonstrating how you can perform the clicking and reading of an HTML control in Internet Explorer using Ranorex with C# (.NET)

I figured out how to start and close the browser, but when I called the control list it only showed me 14 controls which all belonged to IE itself, but I could not figure out how to get to the HTML controls displayed by the WebBrowser.

Do you have an example, e.g. google a word and check the list of links returned? If this works, I will get rid of my Rational Robot licenses =;O)

thanX
TOJZ

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Tue Aug 15, 2006 6:34 pm

Ranorex supports active accessibility, most of the IE controls supports active accessibility also.
You can check this with RanorexSpy, drag the finder tool over the webpage and check the properties of the elements.

You should use the Element functions to automate the controls in IE.

The following sample searches an instance of the IE, activates it, googles the text Ranorex and dumps out all found items:
(Sample project: RanorexVS2005Sample5)

I found a little bug in the Version 0.9.2, I corrected it immediately and made a V0.9.3 Beta1.
Please use this version if you use elements in a web page.
Download: http://www.ranorex.com/download/Ranorex-0.9.3-Beta1.zip

Code: Select all

// Use RanorexSpy to get the class and element properties
Form form = Application.FindFormTitle("Microsoft Internet Explorer",SearchMatchMode.MatchSubstring);
if (form == null)
{
    Console.WriteLine("Cannot find IE");
    return -1;
}

Console.WriteLine("Application found");
form.Activate();

// Find the address box of IE
Control addressBox = form.FindClassName("Edit");
if (addressBox == null)
{
    Console.WriteLine("ERROR: Cannot find IE address box");
    return -2;
}

// Select the actual address
Mouse.ClickControl(addressBox);
//addressBox.Text = "http://www.google.com";
addressBox.SendKeys("http://www.google.com{ENTER}");

Application.Sleep(2000);

Control explorerControl = form.FindClassName("Internet Explorer_Server");
if (explorerControl == null)
{
    Console.WriteLine("ERROR: Cannot find Internet Explorer_Server");
    return -3;
}

//String googleButtonText = "Google-Suche";
String googleButtonText = "Google Search";
Element googleEditBox = explorerControl.Element.FindChild(Role.Text, googleButtonText);
if (googleEditBox == null)
{
    Console.WriteLine("ERROR: Cannot find google search edit box");
    return -4;
}

googleEditBox.Value = "Ranorex";

Element googleSearchButton = explorerControl.Element.FindChild(Role.PushButton, googleButtonText);
if (googleSearchButton == null)
{
    Console.WriteLine("ERROR: Cannot find google search button");
    return -5;
}

googleSearchButton.DoDefaultAction();

Application.Sleep(3000);

DumpElementTree(explorerControl.Element, 0);
The DumpElementTree looks like this:

Code: Select all

static public void DumpElementTree(Element element, int level)
{
    level++;
    int childCount = element.GetChildCount;
    for (int index = 0; index < childCount; index++)
    {
            string spaces = new string(' ', 2 * level);
            Element child = element.GetChild(index);
            if (child == null)
                continue;

            Console.WriteLine("{0}Role={1} Name={2} Value={3}",spaces, child.Role.ToString(), child.Name, child.Value);
            DumpElementTree(child, level);
    }
}
If you use a german IE, you should use googleButtonText = "Google-Suche".
Please contact me if you have a problem.

Jenö Herget
Ranorex Team

nbplopes
Posts: 2
Joined: Thu Nov 16, 2006 3:10 pm

Looking for HTML Controls without a Name

Post by nbplopes » Thu Nov 16, 2006 3:26 pm

Hi there, I'm building an automated test tool for web sites using Ranorex. That is my current assignement.

Is there a simple solution to locate controls and select them without a name. For instance, in some sites input boxes do not have a name (Used Ranorex Spy. In this case what is the best way to get the control. Another example are combo boxes (Class: Internet Explorer_TrindentCmboBx).

Best regards,

Nuno
PS: Great library, but it seams I'll not be able to automate teste over any site.

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Thu Nov 16, 2006 8:57 pm

If the website developer gives a unique name for the elements of the page then it can be automated easily with Ranorex.

If some elements have no names then you can find them with the FindChild(Role,Name,ClassName,Location) function.
You can use the Role, ClassName and Location properties to identify an element.

Gabor Herget
Ranorex Team

nbplopes
Posts: 2
Joined: Thu Nov 16, 2006 3:10 pm

Post by nbplopes » Thu Nov 16, 2006 11:06 pm

Thank you for this nice framework. I'll for sure buy once it reaches 1.0. Meanwhile one last question.

Can the framework control scroll bars? If yes, how?

The reason why I'm asking is that at the moment i'm trying to make a homemade solution to Capture/Playback user interactions with the IE on a WebSite.

I guess in some web sites I'll need to playback using thr original browser position and dimention. But not being able to capture/playback interactions with scroll bars that can turn the all thing a half baked solution.

Thanks in advance for any answer.

Nuno

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Sat Nov 18, 2006 12:59 am

You can automate a standard scroll bar as follows, e.g. the scroll bar of Word or Windows Explorer:

Find the scroll bar itself or one of its element with the FindChild() functions.
  • The scroll bar itself (Role: ScrollBar #3)
  • The top or right arrow button (Role: PushButton #43)
  • The bottom or left arrow button (Role: PushButton #43)
  • The scroll box (thumb) (Role: PushButton #43)
  • The page up or page right region (Role: PushButton #43)
  • The page down or page left region (Role: PushButton #43)
The Value property for the scroll bar itself indicates the scroll bar position and is a string that contains an integer from "0" through "100". You can get or set the position with the Element.Value property.
All other scroll bar elements are pushbuttons and can be pressed with the Element.DoDefaultAction function.

The scroll bar of the Internet Explorer is unfortunately not a standard scroll bar. You cannot use the standard elements and functions, you have to write a workaround.

You can capture and playback the Mouse and Keyboard events.

Jenö Herget
Ranorex Team