Page 1 of 1

By class for element location

Posted: Tue Jul 02, 2013 1:49 pm
by atom
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.

Re: By class for element location

Posted: Wed Jul 31, 2013 1:12 pm
by Support Team
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