Page 1 of 1

Finding Adapter for an Element

Posted: Thu May 30, 2013 4:06 pm
by atom
Hiya.

I am building a keyword "action" based framework that will allow testers to write tests in syntax of:

<action> <ranorex xpath> <additional data>

e.g. SET <xpath of a text box> HELLO

To implement this the code behind the action will use the xpath to find the control as a Ranorex.Element
It then needs to convert that in this case to a Ranorex.Text class
What is the best way to do this, is it doing ?

Code: Select all

public void set_method(string xpath, string data) {

  var element = Ranorex.Host.Local.Find<Ranorex.Element>(xpath);
  var text = new Ranorex.Text(element)
  text.TextValue = data;

}
This seems somewhat cumbersome, what I'd like to do is get a list of "supported" adapters for a specific element... is that possible?

Cheers.

Re: Finding Adapter for an Element

Posted: Fri May 31, 2013 8:25 pm
by Support Team
atom wrote:What is the best way to do this, is it doing ?
IMHO for such an approach you would not need adapters at all. Why not just stick to the generic Element class and its Get/SetPropertyValue and InvokeAction methods? :D

Ranorex Spy shows all the attributes an element provides. The "SET" keyword could have another argument specifying the attribute to set (just like the Ranorex Recorder "Set Value" action):
var element = Host.Local.FindSingle(xpath);
element.SetAttributeValue("text", data);
atom wrote:what I'd like to do is get a list of "supported" adapters for a specific element
If you still need that functionality, have a look at the Element.Capabilities property. It lists all the capabilities/adapters an element supports.

Regards,
Alex
Ranorex Team

Re: Finding Adapter for an Element

Posted: Tue Jun 04, 2013 2:21 pm
by atom
Thanks!
Was looking for some old documentation called "Using the element method" that i seem to remember from a version 2! But couldnt find it...