By class for element location

Class library usage, coding and language questions.
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


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


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


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

Re: By class for element location

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


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.