Page 1 of 1

Ranorex loses element

Posted: Wed Oct 23, 2019 12:31 pm
by M500
Hi,

I am automating in web environment and my goal is to remove a table row by clicking on the rows "Remove"-button (see attached pic). Buttons will become visible when you hover the mouse over a table row. In a different code module I move the mouse pointer on the desired table row, so the buttons become visible.

The purpose of this code module is to click on the "Remove"-button (trash can). As you see from the code, mouse pointer is first moved to the "Add"-button and then to "Remove"-button. But for some reason, when mouse pointer is moved to "Add"-button, Ranorex moves the mouse pointer then to the top-left corner of the window, which usually means that it cannot find something. Why?? Why does Ranorex lose the element?

Also if I add after btnAddNewRow.MoveTo(1000); a click action btnAddNewRow.Click();, it never get executed, because the mouse pointer is in top-left corner.
ss.png
            // Move mouse first to "Add new row"- button and then to "Remove"-button
            ButtonTag btnRemove, btnAddNewRow;
            if(repo.RAIsoftNet.PersonPlanning.tblCareNeeds.TryFindSingle("./tbody//button[1]", out btnAddNewRow)) {
            	Report.Info("Info", "Add-button found");
            	btnAddNewRow.MoveTo(1000);
            	
            	if(repo.RAIsoftNet.PersonPlanning.tblCareNeeds.TryFindSingle("./tbody//button[2]", out btnRemove)) {
            		Report.Info("Info", "Remove-button found");
            		btnRemove.MoveTo(1000);
            		btnRemove.Click();
            	} else
            		throw new ValidationException("Remove-button not found");
            	
            } else
            	throw new ValidationException("Add new-button not found");
BR
-Matts

Re: Ranorex loses element

Posted: Thu Oct 24, 2019 7:30 am
by odklizec
Hi,

Are you sure that xpaths behind repo.RAIsoftNet.PersonPlanning.tblCareNeeds, ./tbody//button[1] and ./tbody//button[2] point to correct and visible elements? Could you please share a snapshot (NOT screenshot) of the UI, with visible Remove button?

You can track 'onmouse-hover' elements with Instant Tracking . Eventually, you can store snapshot of entire app (with enabled remove button) from recording. Simply add Create Snapshot action (of entire app) right after the action, which moves mouse over the table row. This should assure that Ranorex creates snapshot of entire app, including loaded an visible 'Remove' button.

Re: Ranorex loses element

Posted: Fri Oct 25, 2019 1:02 pm
by M500
Hi Pavel,

thank you for your reply. Attached is the snapshot. As long the mouse pointer is on the table row, buttons are visible. Buttons can be found in the snapshot xpath .tbody/tr/td[5]/div.


BR
-Matts

Re: Ranorex loses element

Posted: Fri Oct 25, 2019 2:16 pm
by odklizec
Hi,

Thanks for the snapshot. Please post also full xpath behind repo.RAIsoftNet.PersonPlanning.tblCareNeeds, as you have it stored in repository. Thanks.

Generally speaking, I would suggest to replace element indexes, with button title, like this:
//button[@title>'Add new row']
//button[@title>'Remove row']

Re: Ranorex loses element

Posted: Fri Oct 25, 2019 2:43 pm
by M500
Hi,

full xpath to repo.RAIsoftNet.PersonPlanning.tblCareNeeds is .//div[#'CareNeeds_section']/tabletag. Button title is different if another language is used. That's why I'm using indexes.

BR
-Matts

Re: Ranorex loses element

Posted: Mon Oct 28, 2019 9:22 am
by odklizec
Hi,

From the snapshot you posted, everything looks OK and the xpath you are using should work even with indexes? I would still suggest to use button titles instead of indexes. You can either define multiple titles in the xpath (with OR operator) or to use variable and fill it from the data connector for each language.

Also, have you tried to add Chrome to Ranorex whitelist?

BTW, the snapshot you posted is created manually or from recording/code module action? I would suggest to create the snapshot (even multiple snapshots) during the test runtime (just before the failing actions). This could reveal a potential problems, which may not be obvious if the snapshot is created manually.

And one more thing! Could it be that during the mouse move, the add/remove buttons simply disappears, because the mouse moves outside the row's boundary? What about trying "Perform Click" action, instead of mouse move/mouse click? Usually, I don't recommend using Perform Click, because it may not trigger some essential mouse-based events. On the other hand, there are some edge cases, where the Perform Click is actually a better choice ;)

Re: Ranorex loses element

Posted: Mon Oct 28, 2019 10:18 am
by M500
Hi,

snapshot was created from code module during execution. I am able to take the snapshot just before action btnAddNewRow.MoveTo(1000); (see code in first post), which looks like the attached snapshot. If I try to take a snapshot after the action, it fails because the mouse pointer is moved already to the top-left corner of the screen.

I have also tried to perform a Click()-action, but in never gets executed. Also added Chrome to whitelist and changed buttons to use @tilte instead of indexes.

Have to check with the developer about that boundary issue.

-Matts

Re: Ranorex loses element

Posted: Mon Oct 28, 2019 12:06 pm
by M500
Hi,

found a workaround. I'll click on the row, that way the row stays active/selected and the buttons stay visible all the time, even if mouse pointer is not on the row. Thank you for your help.

Br
-Matts

Re: Ranorex loses element

Posted: Mon Oct 28, 2019 12:20 pm
by odklizec
Hi,

You are welcome. Nice to hear you found the workaround ;)

Re: Ranorex loses element

Posted: Mon Oct 28, 2019 12:33 pm
by M500
Hi,

One reason Ranorex does lose the buttons could be, that the buttons are located inside the selected rows last td-element and are pushed with CSS "outside" the td-element in UI. Just a theory.

-Matts