Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch child elements under selected element using Selenium C#

Tags:

c#

selenium

Find the elements bellow the ul element, as per the following sample HTML:

<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>
</ul>
like image 237
jayesh mhatre Avatar asked Dec 19 '22 13:12

jayesh mhatre


1 Answers

 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

like image 166
Moe Ghafari Avatar answered Dec 24 '22 02:12

Moe Ghafari