Page 1 of 1

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

Posted: Thu Jan 10, 2013 5:30 pm
by JayInMA
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

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

Posted: Fri Jan 11, 2013 10:52 am
by Support Team
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)

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

Posted: Fri Jan 11, 2013 12:57 pm
by JayInMA
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

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

Posted: Mon Jan 14, 2013 3:47 pm
by Support Team
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)