tags:

views:

16

answers:

1

Hi

I'm using 20.20.1089, and I'm getting an exception sometime while looping over like this

foreach (TableRow row in table.TableRows) { for (int i = 0; i < row.OwnTableCells.Count ; ++i) { // EXCEPTION INDEX OUT OF RANGE TableCell cell = row.OwnTableCells [i]; } }

Under the debugger, row.OwnTableCells.Count is 0, but the loop index i has been increments. I can get Exception:Object reference not set to an instance of an object.

This happens sometimes only, which is the puzzling part.The webpage is always refreshing automatically after a few seconds. Could this be the cause of it? Is there a way to disable the cache?

Robin

PS. I'm trying to get this posted on Watin mailing list but it seems the moderator is gone missing, and not approving any new registrations.

A: 

Hi your mail was send on the mailing list as well, but for record sake I'll post my answer here as well.

The webpage is always refreshing automatically after a few seconds. Could this be the cause of it?

This indeed is your problem. Following one of the possible scenarios to show you how things can go wrong:

1 - calling row.OwnTableCells.Count => returns the number of elements currently on the page 2 - refresh timer triggers page refresh => page reloaded 3 - due to refresh the row.OwnTableCells collection will return no elements any more since the row which was referenced no longer exists on the page. You might still see the same row in the browser, but that is a new DOM row object created after the page refresh. In your code you/WatiN is still referencing the old row object.

So you should change your logic to take this refresh of the page into account.

HtH, Jeroen

Jeroen van Menen
Thanks, my subscription got approved after I asked the question here.