jayesh mhatre jayesh mhatre - 3 months ago 6
C# Question

Fetch child elements under selected element using Selenium C#

Below is sample HMTL

<ul _ngcontent-nkg-43="" ngmodelgroup="option">
<span _ngcontent-nkg-17="" style="cursor: pointer;">Option 1</span>
<span _ngcontent-nkg-17="" style="cursor: pointer;">Option 2</span>
<span _ngcontent-nkg-17="" style="cursor: pointer;">Option 3</span>

Answer
 var yourParentElement = driver.FindElement(By.XPath(".//ul[ngmodelgroup='option']"));
 var children = yourParentElement.FindElements(By.XPath(".//*"))

This latter call will return all children elements of yourParentElement