Finding Ranorex Path of a System.winforms.forms.control

Class library usage, coding and language questions.
JayInMA
Posts: 10
Joined: Thu Jan 10, 2013 5:10 pm

Finding Ranorex Path of a System.winforms.forms.control

Post by JayInMA » Thu Jan 10, 2013 5:30 pm

Hi,

I am trying to make some tools to help in creating wrappers around some of our forms.

I want to find the Ranorex Path for a given System.winforms.forms control say Button such in code

Code: Select all

   public class Form1 : System.Windows.Forms.Form
    {
        public System.Windows.Forms.TextBox myPathTxt = new System.Windows.Forms.TextBox();
        public System.Windows.Forms.Button doItBtn = new System.Windows.Forms.Button();
        public Form1()
        {
            this.Size = new Size(200, 100);
            this.Text = "Path Finder";

            myPathTxt.Location = new Point(10, 10);
            doItBtn.Location = new Point(10, 30);
            doItBtn.Text = "find path";

            this.Controls.Add(myPathTxt);
            this.Controls.Add(doItBtn);

            doItBtn.Click += new EventHandler(doItBtn_Click);
        }

        void doItBtn_Click(object sender, EventArgs e)
        {
            //find Ranorex path for doItBtn
            myPathTxt.Text="The path for button";
        }
    }
Basically I am trying to find out the code to fill in for the doItBtn_Click event

- Jay

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Finding Ranorex Path of a System.winforms.forms.control

Post by Support Team » Fri Jan 11, 2013 10:52 am

Hello,

You could use the following code to fill in the path in a textbox.
You might need to modify it in order to meet your needs.
myPathTxt.Text = "/form[@title='" + this.Text + "']/button[@text='" + doItBtn.Text + "']";
Regards,
Markus (T)
.
Image

JayInMA
Posts: 10
Joined: Thu Jan 10, 2013 5:10 pm

Re: Finding Ranorex Path of a System.winforms.forms.control

Post by JayInMA » Fri Jan 11, 2013 12:57 pm

Thanks for reply

That was very simple example, where in reality the path to control is very embedded, with a lot of dynamically created controls.

Was hoping there was a more automated route i could take to get the path to use in testing later

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Finding Ranorex Path of a System.winforms.forms.control

Post by Support Team » Mon Jan 14, 2013 3:47 pm

Hello,

I guess you want to get the RanoreXPath of your objects within your application project.
Unfortunately, this is not possible in the same project since Ranorex automation needs to be run in a separate thread. In other words, your user control cannot respond to the Ranorex automation since Ranorex currently uses the thread.

Could you please describe more detailed what you want to do? Which version of Ranorex are you using?
Basically, you would need a running application and a test project that uses UI automation features of your application under test.

Have you already tried to get the RanoreXPath of your objects in Spy?
I recommend you to take a look at our User Guide in order to give you an overview how UI automation works in Ranorex. You could also have a look at our Screencasts or Webinars.

Please let me know if you need further advice.

Regards,
Markus (T)
.
Image