cancel
Showing results for 
Search instead for 
Did you mean: 

Object sometimes doesn't support Exists

SOLVED
Contributor

Re: Object sometimes doesn't support Exists

In my case, I'm testing a webapp in Firefox. (firefox updates are disabled). So I can't understand why this issue happened.

 

And, I have an other PC with the same project (same script, same app, same firefox) and on this PC, everything run fine.

 

This is the code :

function waitRoundedLoader(){
  var page = Aliases.browser.pageFoederisV9;
  refresh_object(Aliases.browser.pageFoederisV9);
  var PropArray = new Array("className","Visible","VisibleOnScreen");
  var PropValue = new Array("animLoading loading-default",true,true);
  var loader = page.Find(PropArray, PropValue, 30, true);
  if(loader.Exists){
    while(loader.VisibleOnScreen == true){
      Delay(100);
    }
  }
}

(note : I use a while loop because autowait not working in my project, I can't use WaitProperty method).

 

The problem is on the "if" : loader.Exists

 

Community Leader

Re: Object sometimes doesn't support Exists

Ok, it is a timing issue that I have seen before based on the code you showed.

PAGE.FIND is something that I never use due to the fact that you are ending up looking for something in the body of the HTML as a windows object and the timing there will work sometimes and some other times will not.

 

Please use Page.NativeWebObject.Find instead to get the HTML object of the element you desire.  That will work everytime.

Also the WaitProperty will work fine and you should never write code like the while loop with a delay below.

 

Cheers

Lino

Contributor

Re: Object sometimes doesn't support Exists

I cannot use WaitProperty because the timeout parameter is not taken in consideration. I don't know why but it always use the autowait setting of my project properties. (which I use it for some other things). But that's not the problem.

 

What the difference of page.find and page.nativeObject.find ? In my code the "page" object refer to a div called Panel("container") (Mapped with the name pageFoederisV9).

Community Leader

Re: Object sometimes doesn't support Exists

Feel free to read the difference between the 2 here

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/page/find-action-page...

 

Cheers

Lino

Community Hero

Re: Object sometimes doesn't support Exists

Hi,

 

Can you provide us with the source code for the getKeyboard() function and let us know what application are you working with (web, desktop, etc.) ?

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Occasional Contributor

Re: Object sometimes doesn't support Exists

Here's the code to get the keyboard. This is a desktop application.

function getKeyboard() {
  var activeView = Aliases.AppName.HwndSource_Window.WindowTouchViewmodelsShellview.ShellView.Grid.ActiveItem
  
  if (activeView.LoginView.Exists) {
    return activeView.LoginView.Grid.SoftKeyboard
  } else if (activeView.HomeView.Exists) {
    return activeView.HomeView.Grid.SoftKeyboard
  } else return null
}

I have tried a couple of other things in my findKey() function. I tried setting the shiftMode before finding the key, and it still crashes. I also tried changing the properties in my FindChild call to look like this

var key = keyboard.FindChild([propertyName, "Exists"], [character, true], 2, true)

And it still failed.

 

To add something else to help, here are some screenshots of the info I'm checking when I set a breakpoint on the line that fails.

 

Locals.pngObject Browser.PNGWatchlist.PNG

 

As you can see, especially from the last one, the object has the property, but it doesn't actually work when calling it.

Community Leader

Re: Object sometimes doesn't support Exists

else return null

This means your function could return null.  You won't be able to get the Exists property, since it's not an actual object with properties.  Try rather returning Utils.CreateStubObject();

 

Edit:

Propertoes...  As apposed to my stubby little toes Smiley Wink


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
Occasional Contributor

Re: Object sometimes doesn't support Exists

Based on your suggestion I added a check for that:

 

  var keyboard = getKeyboard()
  
  if (keyboard == null) return
  
  var key = keyboard.FindChild(propertyName, character, 2, true)

  ...

It still crashes. I didn't think it was a problem with the keyboard anyway, as my last comment shows that the found child exists and is not null.

Community Leader

Re: Object sometimes doesn't support Exists

Ah ! Found it..  I asked a very similar question previously:

 

aqObject.GetPropertyValue object does not exist after an exist check passes

 

@AlexKaras spent some time explaining TCs caching strategy, which may be the cause ?


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
Occasional Contributor

Re: Object sometimes doesn't support Exists

That seems to have done the trick. I might figure out a way to refine it later on to not use the same code twice, but rather make it a call, and to quit trying if it still fails after a refresh. But for anyone in the future curious of a solution, here's how I fixed my error.

function findKey(propertyName, character, shiftMode) {
  var keyboard = getKeyboard()
  
  if (keyboard == null) {
    Log.Error("Keyboard was not found.")
    
    return
  }
  
  keyboard.set_ShiftMode(shiftMode)
  
  var key = keyboard.FindChild(propertyName, character, 2, true)
  
  // Sometimes key.Exists will crash. If it does, catch the error and refresh.
  try {
    if (key.Exists) {
      key.Click()
      
      return true
    }
  } catch (error) {
    key.RefreshMappingInfo()
    
    if (key.Exists) {
      key.Click()
      
      return true
    }
  }
  
  return false
}
New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2
Top Kudoed Authors