Click fails if performed programmatically

Ranorex Spy, Recorder, and Studio.
van9
Posts: 5
Joined: Mon Apr 25, 2016 12:00 pm

Click fails if performed programmatically

Post by van9 » Mon Apr 25, 2016 12:19 pm

hi,

I have a simple structure html structure
<div>
<a>item1</a>
<a>item2</a>
<a>item3</a>
...
...
...
...
<div>

I would like to dynamically click on each aTag so have used user code

Ranorex.DivTag levelbefore = "/dom[@domain='localhost']//div[#'ctl00_tvNavigationn0Nodes']";
//created an adapter

IList<ATag> items = levelbefore.FindDescendants<ATag>();
//called finddescendants

for(int i=0; i<items.Count; i++)
{
//items.MoveTo();
items.Click();
}

The issue is that when the program is run the first click of item1 is successful, and it goes for a toss and clicks somewhere random.
But the same issue is not observed with Moveto() function.
Please let me know what might have gone wrong.

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

Re: Click fails if performed programmatically

Post by odklizec » Mon Apr 25, 2016 3:58 pm

Hi.

I would suggest to add EnsureVisible() before the click action, like this:

Code: Select all

items[i].EnsureVisible()
items[i].Click();
This should make sure the clicked item is visible and ready for click.

Eventually, it may help to split the action into separate MoveTo and Click actions...

Code: Select all

items[i].MoveTo();
items[i].Click();
Mouse Click actually does MoveTo & Click. But in some cases (typically on VMs or remote systems), it's better to split the action into two actions.

Finally, you may try to use PerformClick() method, which does mouse click without moving the mouse...

Code: Select all

items[i].PerformClick();
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

van9
Posts: 5
Joined: Mon Apr 25, 2016 12:00 pm

Re: Click fails if performed programmatically

Post by van9 » Tue Apr 26, 2016 4:50 am

Hi,

Thanks for the prompt reply.
I have tried by using EnsureVisible() and performClick() and all the combinations but the problem still continue to exist.

Is it because Click() function requires a co-ordinate. Because when we manually record using Ranorex studio it gives a co-ordinate. But I wanted something like an automatic clicking of the elements no matter how many items are there.

The error I am getting is :
"00:08.271 Warn Automation

Could not get a valid element rectangle from '{ATag:ctl00_tvNavigationt2}', since the element is no longer valid. "

Ranorex version: 5.3.1
OS: Windows 7 Enterprise

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

Re: App get crashed while tap on element in iOS Instrumented app

Post by odklizec » Tue Apr 26, 2016 6:12 am

Hi,

Could you please post a sample HTML code which we can try? Or at least the Ranorex Snapshot? But in this particular case, working HTML code would be much more helpful.

Are the atags a part of combo box, a tree list or expanding menu container? If so, then you must most probably expand the container before each click?

Also, what exactly do the clicked atags? If they open another page, then this is a most probable reason why they are not clickable? Once the atag is clicked, it does something, that invalidates the original page with atags and so they cannot be clicked. I think it has nothing to do with coordinates?
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