How to access a Toggle or any User Interface object from script properly.

public void RandomMethod()
{
//randomPanel is the 7th child inside UICanvas.
Transform randomPanel = GameObject.Find(“UICanvas”).transform.GetChild(7);

         //toggleButton is a Toggle and the first child of randomPanel 
         Transform toggleButton = randomPanel.gameObject.transform.GetChild(1);
}

How to convert the toggleButton transform to Toggle gameobject ?

Sorry for the trouble found the answer

 public void RandomMethod()
 {
          //randomPanel is the 7th child inside UICanvas.
          Transform randomPanel = GameObject.Find("UICanvas").transform.GetChild(7);
         
          //toggleButton is a Toggle and the first child of randomPanel 
          Transform toggleButton = randomPanel.gameObject.transform.GetChild(1);

       Toggle t =  randomPanel.gameObject.transform.GetChild(1).gameObject.GetComponent<Toggle>();
 }