Clicking/Touching an non-repo element

Ask general questions here.
steven.fitzpatrick
Posts: 13
Joined: Wed Oct 28, 2015 3:54 pm

Clicking/Touching an non-repo element

Post by steven.fitzpatrick » Wed Nov 04, 2015 3:06 pm

Hi all,

I'm working on some Android app tests at the moment & have a calendar style container with today's date in it and those for a week previous & week in the future.

I have used Host.Local.Find and a For Loop to find each element and correct the Xpath. I want to click on each of these elements in turn & carry out some validation on them before moving onto the next. So far I have:
//Counting the elemnts
int dayCount = Host.Local.Find("/mobileapp[@title='androidapp']//form//container[1]/androidelement[@rid='tabBar']//container/text[@rid='text1']").Count; 
   for (int i = 1; i <= dayCount; i++)
            {
            	var dayContainer = Host.Local.Find("/mobileapp[@title='androidapp']//form//container[1]/androidelement[@rid='tabBar']//container[" + i + "]/text[@rid='text1']");
                //Now what here?
                //I'm struggling to get an Android touch to take place here.
            }
Once I've found the elements I'm lost though, can anyone advice on the next step?

Many thanks,
Steven

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Clicking/Touching an non-repo element

Post by odklizec » Thu Nov 05, 2015 9:03 am

Hi,

I think you don't have to count the found elements. Use 'foreach' instead.
Try the below code...
IList<Ranorex.AndroidElement> elementList = Host.Local.Find<Ranorex.AndroidElement>("/mobileapp[@title='androidapp']//form//container[1]/androidelement[@rid='tabBar']); //create list of found android elements
foreach (Ranorex.Button element in elementList)  //enumerate previously found list of elements and touch each of them...
{  
	Report.Log(ReportLevel.Info,"Touching element: " + element.Text);
	element.Touch()
}
For more code samples check below link, eventually, search this forum...
http://www.ranorex.com/support/user-gui ... html#c3202
Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

steven.fitzpatrick
Posts: 13
Joined: Wed Oct 28, 2015 3:54 pm

Re: Clicking/Touching an non-repo element

Post by steven.fitzpatrick » Thu Nov 05, 2015 10:24 am

Excellent. Thanks very much, your code worked once I'd edited the xpath slightly and and changed the foreach to 'Ranorex.AndroidElement'
foreach (Ranorex.AndroidElement)
Many thanks

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Clicking/Touching an non-repo element

Post by odklizec » Thu Nov 05, 2015 10:30 am

Ah sorry, my mistake ;) I'm not using Android and just automatically typed Ranorex.Button :) I'm glad the code helped!
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration