Forum Discussion

ashutosh01's avatar
ashutosh01
Contributor
2 years ago

Not able to find object

In my script using findall method but it is not working as expected sharing piece of code below:

var lockConnectedFlag = 0
Aliases.javaw.stageLockConfigurationTool.scene.topLevelTabPane.labelDiagnostics.Click()

var j = 0
var v = null;
Delay(5000)
var LockList = Aliases.javaw.stageLockConfigurationTool.scene.topLevelTabPane.rightLockListView

var LockCount = GetPropertyValue(LockList, "wRowCount")

for (i = 0; i < LockCount; i++) {
var prop = new Array("JavaFullClassName", "JavaFXObjectIndex")
var value = new Array("javafx.scene.control.TableRow", i)
v = LockList.FindChild(prop, value, 100)

var prop1 = new Array("JavaFullClassName", "columnIndex")
var value1 = new Array("com.assaabloy.lct.ui.util.LctGuiUtil$2$1", 1)
var SNum = v.FindChild(prop1, value1, 100)
Delay(5000)
var SerialNum = aqObject.GetPropertyValue(SNum, "JavaFXObjectText")
do {
var SerialNum = aqObject.GetPropertyValue(SNum, "JavaFXObjectText")

}
while (SerialNum == "") {
Log.Message("Trying to get the Lock serial no")
}
Log.Message(SerialNum)
if (LockSerialNumber == SerialNum) {
Delay(2000)
var prop2 = new Array("JavaFullClassName", "columnIndex")
var value2 = new Array("com.assaabloy.lct.ui.custom.DiagnosticsTableActionCell$1", ‌‌
var Action = v.FindChild(prop2, value2, 100)

var prop4 = new Array("JavaFullClassName", "columnIndex")
var value4 = new Array("com.assaabloy.lct.ui.custom.DiagnosticsTableActionCell$1", ‌‌

var prop3 = new Array("JavaClassName", "JavaFXObjectName", "JavaFXObjectIndex")
var value3 = new Array("HoverAwareImageView", "diagnoseButton", 0)

var Advancebutton = Action.FindChild(prop3, value3, 100)
if (Advancebutton.WaitProperty("Exists", "true", 10000) == true) {
Advancebutton.Click()

} else {
Log.Message("Diagnose button is not enabled")
}

 

so in above piece of code Advancebutton always comes as false but i have checked its prop and values are matching when i checked with object spy tool.

still code seems correct but adavacnebutton click never happens.

for the same Desktop app in previous versions only the JavaFXObjectName name is changed but still in previous versions it works but not in latest version of desktop app.

may be this is testcomplete issue as you can also see a while condition where i am not getting property value unless i run infinite loop.

so is this an issue with Testcomplete ?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Within your code, can you insert Sys.HighlightObject(Advancebutton)

     

        var Advancebutton = Action.FindChild(prop3, value3, 100);
        Sys.HighlightObject(Advancebutton);
        if (Advancebutton.WaitProperty("Exists", "true", 10000)) {
            Advancebutton.Click();
        } else {
            Log.Message("Diagnose button is not enabled")
        }
    

     

    Is it highlighting the correct control?

     

    Also, is it necessary to check for Exists? Can you not just do,

     

       var Advancebutton = Action.FindChild(prop3, value3, 100)
       if (Advancebutton.Exists)
          Advancebutton.Click();
    

     

     

    Also, can you use the 'insert/edit code sample' button, and format your code

    so it's makes it easier for us to read.

    • ashutosh01's avatar
      ashutosh01
      Contributor

      I did tried your way but not working 

      Highlightobject is not highlighting anything.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If the object is not being highlighted, then it means it's not able to find the advance button with the property values you have provided

     

    You are also not checking the returned object exists for v, SNum and Action,

    var v = LockList.FindChild(prop, value, 100)
    var SNum = v.FindChild(prop1, value1, 100)
    var Action = v.FindChild(prop2, value2, 100)

     

    I'm curious to know, what this code is supposed to do?

    var SerialNum = aqObject.GetPropertyValue(SNum, "JavaFXObjectText")
    do {
    var SerialNum = aqObject.GetPropertyValue(SNum, "JavaFXObjectText")
    
    }
    while (SerialNum == "") {
    Log.Message("Trying to get the Lock serial no")
    }
    Log.Message(SerialNum)

     

    I suggest you debug you code, and step through each line to see what is actually going on.

    • ashutosh01's avatar
      ashutosh01
      Contributor
      var v = LockList.FindChild(prop, value, 100)
      var SNum = v.FindChild(prop1, value1, 100)
      var Action = v.FindChild(prop2, value2, 100)

      I checked this returns right object Highlightobject worked after restarting 

      var SerialNum = aqObject.GetPropertyValue(SNum, "JavaFXObjectText")
      do {
      var SerialNum = aqObject.GetPropertyValue(SNum, "JavaFXObjectText")
      
      }
      while (SerialNum == "") {
      Log.Message("Trying to get the Lock serial no")
      }
      Log.Message(SerialNum)

      Here I am using while because initially SerialNum gives blank but it should return a  value so unless it  fetches a value i keep it running

      It get stuck on Advancebutton as it Exist property is coming false not sure why I have dubugges as well but nothing fruitfull
      so for now I have implemented to image to click and it is working.

  • Exists property and Enabled property are not the same thing. You are waiting at the end for Exists but what you want to wait for is Enabled. 

     

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    JavaScript syntax for do..while statement is,

     

    do {
      code block to be executed
    } while (condition);

     

    and while statement is,

     

    while (condition) {
      code block to be executed
    }

     

    What you have written is not correct and confusing, hence I raised the question.

     

    With regards to your Advance button, does it appear after you performed certain actions? Or is the button disabled and then becomes enabled? TC will execute the lines of code quickly, and your object may not appear in time, therefore you might need a delay or wait. 

     

    An Object can Exists, but it's property values Visible might be False. Meaning that it doesn't appear on screen. You can verify this using the Object Browser.