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

Eat, Sleep, Automate. REPEAT !

Tagged with: , , , , , , , ,
Posted in LeanFT
7 comments on “LeanFT C# Tutorial Part 5 – Find Child Objects
  1. Praveen says:

    How do I do this in java .

    • 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

  2. Roman Draliuk says:

    Hello ,

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

    Thanks
    Roman

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Blog Stats
  • 168,130 hits
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 796 other followers

%d bloggers like this: