Page 1 of 1

Dynamic Number in Table is not getting captured

Posted: Wed Jul 15, 2015 6:38 pm
by javier.calderon
Hello,

I am trying to get a VIN number from the table. The problem is the spy recognizes the object based on the innertext of that element. The problem is that once I process a payment that VIN is no longer available. When I try to run the test again Ranorex gets stuck because it cannot find the innertext. I need it to just grab any VIN and be able to make that a variable. I have attached screen shots.

Re: Dynamic Number in Table is not getting captured

Posted: Thu Jul 16, 2015 9:59 pm
by odklizec
Hi,

I'm not sure what exactly you want to achieve? Get all VINs from the table and then what?

It should be possible to obtain all VINs (and store them in a list of strings) using a carefully constructed xpath, containing "VIN:" string? Unfortunately, it's hard to create such xpath without seeing the Ranorex snapshot of given table. If you cannot/don't want to upload the snapshot publicly, try to send it to [email protected].

Re: Dynamic Number in Table is not getting captured

Posted: Fri Jul 17, 2015 3:31 pm
by javier.calderon
I just need it to capture any VIN in that table and assign it to a variable. Ideally I just need to be able to look at the table and say go to Row1, Column 3 get that VIN(which changes all the time) and assign it to a variable. I just need a way to capture that dynamic field because once I process a VIN that entry disappears from the table.

Re: Dynamic Number in Table is not getting captured

Posted: Fri Jul 17, 2015 4:26 pm
by krstcs
Try changing your RanoreXPath to use something besides the innertext attribute when identifying the element you need.

You can use the column number if you have to (but using indexes like that can cause things to be brittle in the long run, such as if the developers change the column order). You could use Regex to find the cell with both 'VIN' and 'STK' in the text. Then grab the innertext and parse out the actual vin in usercode.

/div[@innertext~'VIN' and @innertext~'STK']

Without seeing a snapshot of the structure it is hard to help though, as Pavel said. :D

Re: Dynamic Number in Table is not getting captured

Posted: Fri Jul 17, 2015 5:05 pm
by javier.calderon
Here is the snapshot.

Re: Dynamic Number in Table is not getting captured

Posted: Fri Jul 17, 2015 5:55 pm
by krstcs
/dom[@domain='test.nextgearcapital.com']//table[#'paymentsSearchTable']/tbody/tr[1]/td[@class='description-narrow']/div/p/span/span[@innerText='VIN']

That path will find the span with innertext='VIN' in the 1st row ('tr[1]') of the table.

You should probably look into using rooted folders for the table and each row. Then you would use the XPath that gets you the row you want for the row folder. Inside that you could have repo items for each of the columns or pieces of info inside the columns, depending on what you need to do.

Re: Dynamic Number in Table is not getting captured

Posted: Fri Jul 17, 2015 6:18 pm
by javier.calderon
When I run it this just returns the value VIN and not the number sequence. Is there a way to just capture the actual numbers?

Re: Dynamic Number in Table is not getting captured

Posted: Mon Jul 20, 2015 7:33 am
by odklizec
Hi,

I would suggest to use xpath like this:

Code: Select all

/dom[@domain='test.nextgearcapital.com']//table[#'paymentsSearchTable']/tbody/tr/td[@class='description-narrow']/div/p/span/span[@innertext='VIN']/../../span[@innertext~'.*']
The regex in last span is a rough one. You should have to find/construct a correct regular expression for VIN numbers validation. But for now, the one from my example should do the trick ;)

The above path will return all spans containing VIN numbers.

What you need to do now is to process the list of obtained spans, to obtain the individual VIN numbers and do whatever you want with them. You can use something like this:
public void GetVINNumbers(Ranorex.Core.Repository.RepoItemInfo spanTagVIN)
        {
        	// Create a list of adapters using the "Info" object  
			IList<Ranorex.SpanTag> spanList =   
			    spanTagVIN.CreateAdapters<Ranorex.SpanTag>();  
			  
			// Get VIN number from each found span and print it in Report      
			foreach (Ranorex.SpanTag spanVIN in spanList )  
			{  
			    string vinValue = spanVIN.InnerText;  
			    Report.Info("Available VIN number: " + vinValue);
			}   
        }
Hope this helps?

Re: Dynamic Number in Table is not getting captured

Posted: Mon Jul 20, 2015 2:34 pm
by krstcs
Yeah, sorry, I should have added that you would need to get the actual value of the VIN by making an XPath based off what I posted.

Thanks Pavel for adding that. :D

I would suggest learning as much about XPath and how Ranorex uses it as you possibly can, as well as learning RegEx. There are many problems in Ranorex automation that can be solved by the proper application of those technologies. In my opinion, these are the most important things to learn with Ranorex.

Re: Dynamic Number in Table is not getting captured

Posted: Thu Jul 30, 2015 2:38 pm
by javier.calderon
Thanks. I was able to get the value from using span[@innertext~'.*'] at the end. It grabs whatever the first value is.