Ask a Question

How to Map a JS Element

GabrielHabib
New Contributor

How to Map a JS Element

Hello, I'm having some trouble when trying to map some features from my WebSite. Actually, if I start capturing a moviments in my webSite the TestComplete doesn't recognize at all lots of screens. What I decided to do was trying to map some elements and once I know them, I while waiting them appear, or desappear... Well, I was going good till I reach this part :

 

TesteComplete.png

 

I couldn't find a way to map the "Loading". I could use Delay in stead of waiting the page to be charged, but I don't want to tie up my test with lots of delays.

10 REPLIES 10
baxatob
Community Hero

Re: How to Map a JS Element

Did you try to refresh object browser before mapping?

Colin_McCrae
Community Hero

Re: How to Map a JS Element

When you say you can't find a way of mapping it, do you mean:

 

1. It does not appear in the object browser. At all.

2. You can't find any properties to identify it reliably.

 

I presume this is a transient object? ie. it only exists while loading is happening and is not present in the DOM at any other time? (rather than just being hidden) Objects like this can be a little awkward to work with. The CTRL+SHIFT+A mapping method is usually your friend here ....

GabrielHabib
New Contributor

Re: How to Map a JS Element

Not Really, once it is transient

GabrielHabib
New Contributor

Re: How to Map a JS Element

I can't find any properties to identify it reliably.

 

You are right, this is transient, well, I tried to work with CNTRL SHIFT A, but look to the image, it says the object doesnt exist 😞

 

 

 

AlexKaras
Community Hero

Re: How to Map a JS Element

Hi,

 

You may consider slightly different approach: I am taking that this 'Loading...' frame is displayed while the underlying Customers table is populated with data. If the above is correct, you may try this:

-- Identify the Customers table;

-- Wait until its number of rows is greater than zero and do not change within, say, a second. When this condition is met, this means that the table was populated with data and data are no more added to the table (in case this is done via some script and requires some complex processing).

-- The above point assumes that if the table does not contain data at all, this is indicated somehow and can be identified from test code.

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
GabrielHabib
New Contributor

Re: How to Map a JS Element

Hello Alex, I appreciate your answer, however, the point is, as soon as I log into the system the table is automatically filled, and when I change the tab the system re fill the SAME table. In this case, I would wait two "loadings", but the number of elements(rows) would be same, less, bigger.... Well, I do agree I could use Delays, however, sometimes the system gets 5 seconds, others it gets 50secs....

 

 

 

Colin_McCrae
Community Hero

Re: How to Map a JS Element

Your screen capture with "Object does not exist" refers to an Alias? Which would imply you already have a mapped object for it ... which doesn't work properly?

 

In which case, can you delete the current mapped object (which doesn't work - so no loss).

 

Then do a CTRL + SHIFT + A object spy (make sure you spy it, not map it - although I'm not sure it should make a difference) on it again. This should capture the properties at the point you map it. Even if it vanishes after that, you should still have the properties that were present when you spied it.

 

Don't try and drill down within any of the properties, that will probably cause it to lose/clear the object.

 

Do that, and then post the properties here.

 

I'm thinking you could .....

 

1. Simply put it in a double loop as soon as you activate whatever triggers it. One (very fast repeating) loop until it spots it. Then a second loop that waits for it to go.

2. Identify it by something simple such as classname (assuming there are no other elements in the DOM of the same class).

3. If using 1 &2, I would probably do all this dynamically and not map it.

4. If you *really* need to map it, your best bet is likely the caption (if it's text) or the image file name (if it's an image and the filename is exposed in the properties somewhere).

 

Without the element to look at ourselves, it's tricky to say.

AlexKaras
Community Hero

Re: How to Map a JS Element

> [...] when I change the tab the system re fill the SAME table [...]

Not sure that I got your concern... Maybe I was not clear enough. Pseudo-code algorithm is like this:

-- Enter the page/tab you need;

-- Identify the table;

-- Get the current number of records in the table (iPrevNoOfRecords);

-- Get current time (startTime);

-- Enter the loop;

-- Wait 0.5 sec (or more as appropriate to get a stable code but not to wait too much);

-- Get the current number of records in the table (iCurNoOfRecords). If the number is greater than iPrevNoOfRecords then update iPrevNoOfRecords with the new value;

-- Get current time (currTime);

-- Exit the loop if either iPrevNoOfRecords == iCurNoOfRecords or the timeout (currTime -  startTime) is elapsed. Otherwise continue the loop;

-- Depending on whether the loop was exited because no new record was added to the table or timeout elapsed, continue with the test (former case) or log an error/warning that the table was not populated with data within (timeout) interval (the latter case).

 

Works reliably for me in several web projects.

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Colin_McCrae
Community Hero

Re: How to Map a JS Element

Alex .... I think the problem with that approach is:

 

  • "but the number of elements(rows) would be same, less, bigger"

So if it could return a table of the same size you are down to what is effectively a hard coded delay (whatever the timeout on your loop is) so no better than using a basic Delay(). It's an update, rather than a load from nothing. So it could update from 10 rows to the 10 rows again. Rowcount doesn't change. Loop simply times out ....

 

I'm wondering if you could possible also look at the page ReadyState? It depends how it's loading and whether that's reflected in the page ReadyState ....

 

(And also if Chrome - if that is the browser in use - have fixed the bug where it ALWAYS returns ready, regardless whether it actually is or not ...)

cancel
Showing results for 
Search instead for 
Did you mean: