LeanFT C# Tutorial Part 5 – Find Child Objects

If you have worked with UFT/QTP, you must be pretty familiar with the ChildObjects method but in case you have not, this method is used to find a collection of objects that match a given set of description properties.

For example, if you google “leanft tutorial”, and you want to find out how many links are redirecting to this blog, you will have to write code in the following way:-


var links = browser.FindChildren<IWebElement>(new WebElementDescription
{
   TagName = @"CITE",
   InnerText = As.RegExp(@".*learn2automate.wordpress.*"),
});

//Check that atleast one link should be present
Assert.AreNotEqual(0, links.Length);

So here the ChildObjects method(from UFT) is replaced by the FindChildren method and the logic more or less remains the same.

Please comment if you face any issues while executing this.

LeanFT C# Tutorial Part 6 – Parameterising Tests

Happy Automating!
Harshit Kohli

Advertisements

7 thoughts on “LeanFT C# Tutorial Part 5 – Find Child Objects

    1. Hi Praveen,

      Here you go:-

      //I’m using XPathDescription here, you can use an other Description type also
      XPathDescription sectionDescrption = new XPathDescription(“//span[@class=’widget_header’]”);

      //Fetching an array of objects matching the above description
      WebElement[] sections = browser.findChildren(WebElement.class,sectionDescrption);

      Hope this helps.

      Thanks,
      Harshit

  1. Hello ,

    How should you switch to the new window that open ?
    There is no option of window handeler like in selenium

    Thanks
    Roman

      1. You can use the same approach for IE for attaching if you are launching browser with LeanFT.

        If you are launching with Selenium, you need to understand that IE doesn’t work with Profiles as in the case of Chrome. So you don’t need to add the LeanFT extension when launching the InternetExplorer Driver. You will be able to attach to the IE browser without adding any extended capabilities.

        Regards,
        Harshit Kohli

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s