By class for element location

Class library usage, coding and language questions.
atom
Posts: 357
Joined: Sun Dec 07, 2008 11:14 pm
Location: Dublin, Ireland

By class for element location

Post by atom » Tue Jul 02, 2013 1:49 pm

Hello.

I was wondering if anyone has wrapped the Find methods to have something similar to the By class in selenium. e.g.

Form.Find<Ranorex.Text>(By.Id("105"))
Form.Find<Ranorex.Button>(By.Text("OK"))

where say:
By.Id("105") expands to xpath string descendant::element[@id="105"]

Cheers.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: By class for element location

Post by Support Team » Wed Jul 31, 2013 1:12 pm

Hello,

You can do this using Ranorex, you just need to use the appropriate RxPath and search method.
Here is a sample how this can work:
Ranorex.Text text = Form.FindSingle<Ranorex.Text>(".//text[@?'105']");
If you know which attribute contains the Id you can also add it to the RxPath:
Ranorex.Text text = Form.FindSingle<Ranorex.Text>(".//text[@controlid='105']");
It is also possible to use a variable instead of the hard coded id:
String Id = "105";
ATag tag = newsORFAt.FindSingle<Ranorex.ATag>(".//a[?'"+Id+"']");
The same holds for finding an element by its text.

Regards,
Markus