Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Selenium C获取选定元素下的子元素#_C#_Selenium - Fatal编程技术网

C# 使用Selenium C获取选定元素下的子元素#

C# 使用Selenium C获取选定元素下的子元素#,c#,selenium,C#,Selenium,根据以下示例HTML查找ul元素下面的元素: <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>

根据以下示例HTML查找
ul
元素下面的元素:

<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>

选择1
选择2
选择3


如果试图获取
span
元素,可以执行以下操作:
driver.FindElement(按.Xpath(“.//ul[ngmodelgroup='option']”)


后一个调用将返回parentElement的所有子元素

您可以通过
CssSelector
执行此操作吗?这是一个延迟响应,因此这适用于所有寻求类似问题的人。在此上下文中,cssSelector可以通过driver.FindElements(By.cssSelector(“ul[ngmodelgroup='option']>span”))来解决。
 var yourParentElement = driver.FindElement(By.XPath(".//ul[ngmodelgroup='option']"));
 var children = yourParentElement.FindElements(By.XPath(".//*"))