小编sal*_*d11的帖子

XPath 查找子元素的父元素

我有这样的结构:

<div class="Container">
  <div class="HighlightContainer">
    <div class="NodeTextHighlightContainer">
      <span class="TreeItemSelected">Products</span>
    </div>
    <button class="ContainerSelectedMenu" type="button"></button>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

由于 DOM 的行为方式并试图保持动态,我只能定位包含文本产品的范围。使用类似的东西:

Driver.FindElement(By.XPath("//div[contains(@class, 'Container')]/descendant::span[text() = 'Products']"));
Run Code Online (Sandbox Code Playgroud)

但是,我需要class="ContainerSelectedMenu"根据该跨度元素定位按钮,最好的方法是什么?类似于获取 Container 子元素的父 div 然后找到按钮元素。

html c# selenium xpath

4
推荐指数
1
解决办法
8064
查看次数

标签 统计

c# ×1

html ×1

selenium ×1

xpath ×1