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

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
joachimr
Posts: 4
Joined: Fri May 29, 2015 3:26 pm

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

Post by joachimr » Wed Jan 16, 2019 4:15 pm

Hello Ranorex uers,

since a couple of weeks we see a non-reproducable issue which shows up in random places:
"Could not get a valid element rectangle from '{TreeItem:}', since the element is no longer valid"
As a consequence we can for example not click the element.

It happens in different areas of the AUT on different object types (treeitems, buttons, texts, tabpage...)

I browsed forum and followed suggestions like adding "@enabled='true'" to RanorexPath, but this did not help.

When it happens:
  • we can see element in screenshot
  • either the valid flag of adapter is false or the ScreenRectangle is 0,0,0,0
  • we capture a snapshot of the adapter at runtime and in Spy it will be marked as red and "invalid"
  • a workaround of recreating adapter based on the RanorexPath of the old adapter does work (e.g. the UI element is there...):

Code: Select all

newAdapter = new Button(oldAdapter.GetPath(PathBuildMode.Simple).ToString());						
newAdapter.Click();
Questions:
  • any suggestion how to narrow down the root cause of the issue (we can't have above workaround all over the place...)
  • is there a way to catch the "Could not get a valid element rectangle ..." warning in user code?
  • is there a way to suppress the warning ?
Thanks a lot for your help!
Joachim

Environment:
* Ranorex 8.3.1
* Win10
* WinForms AUT

ahoisl
Certified Professional
Certified Professional
Posts: 175
Joined: Fri Sep 07, 2007 8:16 am

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

Post by ahoisl » Wed Jan 16, 2019 11:04 pm

You usually get that message when the Ranorex element is no longer valid, i.e. if the real UI element corresponding to the Ranorex element is not there any more. With WinForms controls this happens if the window handle of the control changes, e.g. due to the control being disposed or recreated (which may happen if the control layout changes).

Is this happening with user code, recorder, or repository items?

If this happens with user code, which I suspect, try to not keep element instances for a long time period or after user interaction where controls go out of scope, i.e. get invisible/disposed. The safest way is to always get elements directly from the Ranorex repository; it will automatically cache elements and re-search them using the RanoreXPath if needed (if "Use Cache" is enabled).

Regards,
Alex
Ranorex Team

joachimr
Posts: 4
Joined: Fri May 29, 2015 3:26 pm

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

Post by joachimr » Thu Jan 17, 2019 1:58 pm

Hi Alex,

thanks for your feedback!
Yes, this is happening with user code.

>> try to not keep element instances for a long time period or after user interaction where controls go out of scope, i.e. get invisible/disposed.
>> The safest way is to always get elements directly from the Ranorex repository

So will below code snippet be problematic, if creation of the pagobject and usage of BringChannelsRibbonIntoView() are happening at very different points in time?
I was under the impression that Tabpagechannels would be evaluated when using it ?
(and that value of "UseCache" of folder "ContainerRibbonTabs" in repository would only impact speed)

Code: Select all

	public class PageObjectChannelsRibbon
	{
		private Base.RepositoryFolders.ContainerRibbonTabsFolder _ribbonTabs = 
					Base.Repository.Instance.ContainerRibbon.ContainerRibbonTabs;

        	//...

		/// <summary>
		/// Bring the Channels Ribbon into View
		/// </summary>
		public void BringChannelsRibbonIntoView()
		{
			_ribbonTabs.TabpageChannels.Click();
		}
Thanks again for your help
Joachim

ahoisl
Certified Professional
Certified Professional
Posts: 175
Joined: Fri Sep 07, 2007 8:16 am

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

Post by ahoisl » Thu Jan 17, 2019 2:30 pm

As far as I can tell from the snippets, your are indeed using a Ranorex repository here. The repository should already care about searching for a cached folder element again if needed, so IMHO this looks safe.

And yes, if the "TabpageChannels" is just referencing an item from a Ranorex repository (cannot tell 100% from the snippet), it will search for the element using the path again. Depending on whether a parent folder was already searched before (and only if "Use Cache" is true), the search will be relative from the former cached parent folder.

Regards,
Alex
Ranorex Team

joachimr
Posts: 4
Joined: Fri May 29, 2015 3:26 pm

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

Post by joachimr » Thu Jan 17, 2019 2:52 pm

>> if the "TabpageChannels" is just referencing an item from a Ranorex repository (cannot tell 100% from the snippet),
I can confirm its just an item in the repo.

Would you expect any functional problem if folder "ContainerRibbonTabs" has UseCache=false ?

Because this is the current config and still I'm seeing the sporadic "Could not get a valid element rectangle from '{TabPage:}', since the element is no longer valid"

Thx
Joachim

ahoisl
Certified Professional
Certified Professional
Posts: 175
Joined: Fri Sep 07, 2007 8:16 am

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

Post by ahoisl » Thu Jan 17, 2019 10:22 pm

joachimr wrote:
Thu Jan 17, 2019 2:52 pm
Would you expect any functional problem if folder "ContainerRibbonTabs" has UseCache=false ?
No, it would even make it less likely to get invalid elements since the item/folder will then always be searched again when accessed.

Try to switch off "Use Cache" for the app folder that the problematic item resides in. This will turn of caching for all items/folders underneath it. If that helps, you can try to enable caching again and just turn it off for a more direct ancestor rooted folder of the item.

And can you provide a snapshot of the failing control, please? It would be nice to see which technology the AUT is made with.

Regards,
Alex
Ranorex Team

joachimr
Posts: 4
Joined: Fri May 29, 2015 3:26 pm

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

Post by joachimr » Mon Jan 21, 2019 2:18 pm

Hi,

>>Try to switch off "Use Cache" for the app folder that the problematic item resides in.
>>This will turn of caching for all items/folders underneath it.
>>If that helps...
No (it already was swicthed off).

I've been sending the snapshot to [email protected] (with reference to this thread).
It is one of the simpler places where the issue occurs (plain button).


Thx
Joachim