Page 1 of 1

IList; is it possible to refresh?

Posted: Tue Jun 12, 2018 12:01 pm
by agroenen
We have a few screens where repository-items are visible multiple times.
This code clicks on all of them:

Code: Select all

            public void ClickAlleElementen(Ranorex.Core.Repository.RepoItemInfo K2WItem)  
            {

            	IList<Unknown> elementList = K2WItem.CreateAdapters<Unknown>();  
                  
            		foreach (Ranorex.Unknown element in elementList)
                		{  
                    		element.Click();
                		}	
            }
But sometimes clicking on the element means deleting; so the element isn't on the screen anymore, but still in the list. Then we get an error like "Could not get a valid element rectangle from '{DivTag:}', since the element is no longer valid."

Is there a way to refresh the IList after clicking on an element?

Re: IList; is it possible to refresh?

Posted: Wed Jun 13, 2018 8:51 am
by RobinHood42
Hi agroenen,
But sometimes clicking on the element means deleting; so the element isn't on the screen anymore, but still in the list. Then we get an error like "Could not get a valid element rectangle from '{DivTag:}', since the element is no longer valid."
Can you please explain why this could be an issue. Assuming you have fetched 3 elements from your list element. Within the "foreach" you iterate over all of them. Element 1 is clicked and deleted, Element 2 and 3 are just clicked. So, you won't access Element 1 again. Therefore, it's irrelevant if the element was just click or deleted as well. :?:

Would be great if you could provide further information, that would help me to better understand your issue.

Cheers,
Robin :mrgreen:

Re: IList; is it possible to refresh?

Posted: Wed Jun 13, 2018 10:13 am
by ahoisl
agroenen wrote:Is there a way to refresh the IList after clicking on an element?
The only way to "refresh" elements is to search them anew, i.e. by retrieving them again from the repository (which does a search internally).

In your example, this could be achieved by setting the elementList variable again:
elementList = K2WItem.CreateAdapters<Unknown>();
Regards,
Alex
Ranorex Team

Re: IList; is it possible to refresh?

Posted: Thu Jun 14, 2018 3:06 pm
by agroenen
I managed to solve it by using a "while" loop, instead of foreach.
Error isn't coming up in this way.

@RobinHood: I can't explain it better, after the first element is deleted this error comes up. I thought that was maybe because it is still in the list, but I don't understand it either because it shouldn't matter.