Forum Discussion

prasath_2k's avatar
prasath_2k
Occasional Contributor
3 years ago
Solved

How to access all child objects and get its value?

Hi,

I have to check different parameters values like "device name", "reference" etc from the window(Reference image I have attached). To do so I have spied the panel and it has got 26 child objects. Now I have to traverse through child objects and get their value.  Can get_DataContext() function be used? 

 

Experts do pour your comments

 

Thanks!

 

ApplicationObject browser window shows Panel(WPFObject("Grid","",1)) with 26 child objectsCode snippet

4 Replies

  • Mr_Bro's avatar
    Mr_Bro
    Champion Level 0

    prasath_2k ,

     

    Please find the below sample code to print the text of all the child objects under particular parent .

    def sample():
        page = Sys.Browser("*").Page("*")
        arrProp = [] #provide a list of property
        arrValue = [] #provide a list of values
        objParent = page.find(arrProp,arrValue,30)
        iChildCount = objParent.ChildCount
        for each in len(iChildCount):
            Log.Message("Content Text of Child :"+ each + " is : " + str(objParent.Child(each).contentText))
  • sonya_m's avatar
    sonya_m
    SmartBear Alumni (Retired)

    Thanks a lit for helping here, Community!

     

    Hi prasath_2k , please let us know the final solution.

    • prasath_2k's avatar
      prasath_2k
      Occasional Contributor

       

      I took the individual child by using findChild and compared the desired property which I wanted

       

      //checks for scan result window
      let WndScan = Aliases.SoMove_Launcher.ScanWnd;
      if( WndScan.Exists)
      {
      //checks for Scan network btn
      let BtnScan = Aliases.SoMove_Launcher.ScanWnd.ScanDeviceView_WPF.elementHost2.HwndSource_AdornerDecorator.AdornerDecorator.btnScanNetwork;
      if(BtnScan.Exists)
      {
      //clicks on Scan network btn
      BtnScan.ClickButton();
      Delay(1000);

      let Grd_Deviceinfo = Aliases.SoMove_Launcher.ScanWnd.ScanDeviceView_WPF.elementHost2.HwndSource_AdornerDecorator.AdornerDecorator.deviceInfoPnl.grd_DeviceinfoPanel;
      if(Grd_Deviceinfo.ChildCount > 0)
      {
      let ObjImg = Aliases.SoMove_Launcher.ScanWnd.ScanDeviceView_WPF.elementHost2.HwndSource_AdornerDecorator.AdornerDecorator.ScanWnd_DeviceHostpanel;
      Device_img = ObjImg.FindChild("Name", 'WPFObject("btnThumbNail")', 5)

      //Checks for Device image
      if(Device_img.Exists)
      Log.Message("Device image has appeared by scanning");
      else
      Log.Error("Device's image did not appear after scanning");

      //checks for Device name
      let ObjDevice = Grd_Deviceinfo.FindChild("Name",'WPFObject("lblDevieNameValue")',20);
      if(ObjDevice.Content == DeviceName)
      Log.Message("Device Name got displayed as "+DeviceName+" correctly")
      else
      Log.Error("Device Name did not get displayed correctly!!")

      //checks for Device type
      let ObjDevicetype = Grd_Deviceinfo.FindChild("Name",'WPFObject("lblDevieTypeValue")',20);
      if(ObjDevicetype.Content = DeviceType)
      Log.Message("Device type got displayed as "+DeviceType+" correctly")
      else
      Log.Error("Device type did not get displayed correctly!!")

      //checks for Reference
      let ObjRef = Grd_Deviceinfo.FindChild("Name",'WPFObject("lblReferenceValue")',20)
      if(ObjRef.Content = Reference)
      Log.Message("Device's Reference got displayed as "+Reference+" correctly")
      else
      Log.Error("Device's reference did not get displayed correctly!!")

      //checks for DTMversion
      let ObjDTMVersion = Grd_Deviceinfo.FindChild("Name", 'WPFObject("lblDtmVersionValue")', 20);
      if(ObjDTMVersion.Content = DTMVersion)
      Log.Message("Device's DTM version got displayed as "+DTMVersion+" correctly")
      else
      Log.Error("Device's DTM version did not get displayed correctly!!")

      Log.Message("Settings at Device and DTM end Matched!!")

      //clicks on Apply btn on Scan wnd
      if(Aliases.SoMove_Launcher.ScanWnd.ScanDeviceView_WPF.elementHost2.HwndSource_AdornerDecorator.AdornerDecorator.btnApply.Exists)
      Aliases.SoMove_Launcher.ScanWnd.ScanDeviceView_WPF.elementHost2.HwndSource_AdornerDecorator.AdornerDecorator.btnApply.ClickButton();

      }
      else
      Log.Error("Device and DTM settings do not match!!");

      }
      else
      Log.Error("Scan btn did not found!");

      }
      else
      Log.Error("Scan Result window did not open!");

      });