Page 1 of 1

Unable to interact with object collections in a list...

Posted: Wed Jul 23, 2014 9:51 pm
by carsonw
I'm having trouble understanding why this won't work. Conceptually it seems ok, but in practice it does not.

Here is the code:

Code: Select all


var allPaymentsObjects = FileUploadSummaryRepository.Instance.UploadSummary.PaymentTabs.AllPayments;

//This returns a collection of rows which I will iterate through...
var dataRows = allPaymentsObjects.GridData.Self.FindChildren<TrTag>();

foreach (var dataRow in dataRows)
{                
     FileUploadSummaryRepository.Instance.LineItemNumber = counter.ToString();
     var rowData = dataRow.FindChildren<TdTag>()
The above is the start of the for loop. For the FIRST row in the collection "rowData" will be populated with all the data cells (TD) correctly, however when we move to the next iteration (i.e. row 2), then it will never find any children. It's like I have to redo this:

var dataRows = allPaymentsObjects.GridData.Self.FindChildren<TrTag>()

Even though it should already contain all the rows. Somehow it lost the row information. Am I missing something here? I can't just keep getting the dataRows over and over because it will change my iteration (well I could do it in another way, but the above is ideal). Thanks!

Re: Unable to interact with object collections in a list...

Posted: Wed Jul 23, 2014 9:58 pm
by carsonw
Ok - as I was writing this I was thinking about it and did another test and understand better why it doesn't work, but I'm hoping for a more technical reason (which I can't figure out on my own :)).

If I don't interact with the page in any way, then it works fine.

However, I have a series of rows that can be expanded. If I expand and collapse one row, then I can't get any further information without "re-getting" the entire grid. Although, I kind of don't understand why because I did restore the page to its original state (far as I can tell). And if I do it manually (i.e. expand/collapse the rows) and then spy the two existing rows they are found correctly.

Just for my own interest - thanks!

Re: Unable to interact with object collections in a list...

Posted: Mon Jul 28, 2014 4:05 pm
by Support Team
Hi Carson,

This is a problem regarding the reload of the specific grid.

When you search for a web element and save it to a variable and the web page then gets automatically reloaded a new live element will be created. When you now want to access it with the previously created adapter this will no longer work since the saved element targets the old no longer existing live element. In order to be able to use the newly created live element you need to again search for the current live element.
It is therefore recommended to use the Ranorex repository since this ensures that you always work with the current live element since Ranorex always searches for the current live element when you access one of the repository items.
When you access old live elements you should normally get a error message stating that the element is no longer valid. The elements get marked as invalid since they do no longer exist.
Invalid means that the (web)elements on your webpage were updated and the old found elements do no longer exist and therefore the Ranorex representatives (adapters of Ranorex) of the (web) elements are invalid.

I hope I was able to describe this in a understandable way.

Regards,
Markus

Re: Unable to interact with object collections in a list...

Posted: Tue Jul 29, 2014 4:40 pm
by carsonw
Yes - that does help thanks! For my own curiosity - how does Ranorex know that the element changed? The path to the elements remained the same...

Re: Unable to interact with object collections in a list...

Posted: Mon Aug 04, 2014 2:53 pm
by Support Team
Hi Carson,

Ranorex tries to use the established connection to the element and in case the live element does no longer exist the connection fails and Ranorex therefore knows that the element is no longer valid.
So in general Ranorex checks if the remote element is still available.

Regards,
Markus