我正在尝试找到一个像容器一样的元素。我用过css选择器和xpath。但我无法找到元素。有人可以帮忙吗?
这是完整的html代码段
<div class="container" data-aura-rendered-by="44:87;a"><header data-aura-rendered-by="45:87;a">
Klant zoeken
<a href="https://website/image/path/" data-aura-rendered-by="47:87;a"><span class="icon icon-sluiten" data-aura-rendered-by="48:87;a"></span></a></header><section class="wrapper" data-aura-rendered-by="49:87;a"><div class="logo" data-aura-rendered-by="50:87;a"></div><div class="span12 container_12" data-aura-rendered-by="51:87;a"><div class="interactions siteDesignTimeRegion" data-region-name="content" data-allow-drop="true" data-item-id="6365fc9c-51b9-1255" data-aura-rendered-by="6:87;a" data-aura-class="siteDesignTimeRegion"><div class="emptyRegionPlaceholder siteEmptyRegion" data-aura-rendered-by="10:87;a" data-aura-class="siteDesignTimeEmptyRegion">Add components (content)
</div><!--render facet: 18:87;a--></div></div></section></div>
实际容器位于
之下<div class="interactions siteDesignTimeRegion" data-region-name="content" data-allow-drop="true" data-item-id="6365fc9c-51b9-1255" data-aura-rendered-by="6:87;a" data-aura-class="siteDesignTimeRegion">
CSS查找:div.container div.interactions.siteDesignTimeRegion
XPath:/ html / body / div [4] / div [4] / body / div [2] / section / div [2] / div
答案 0 :(得分:0)
您可以使用css或xpath。
用于css:
div.interactions.siteDesignTimeRegion
对于xpath使用:
//div[@class='interactions siteDesignTimeRegion']
在可能的情况下,始终尝试按属性选择元素,并避免使用绝对的xpath,例如您给出的绝对xpath。