Finding Adapter for an Element

Ask general questions here.
atom
Posts: 357
Joined: Sun Dec 07, 2008 11:14 pm
Location: Dublin, Ireland

Finding Adapter for an Element

Post by atom » Thu May 30, 2013 4:06 pm

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.

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

Re: Finding Adapter for an Element

Post by Support Team » Fri May 31, 2013 8:25 pm

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
.
Image

atom
Posts: 357
Joined: Sun Dec 07, 2008 11:14 pm
Location: Dublin, Ireland

Re: Finding Adapter for an Element

Post by atom » Tue Jun 04, 2013 2:21 pm

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...