3

我有以下代码:

<g xmlns="http://www.w3.org/2000/svg" id="MainMenu1" display="block" transform="translate(1125, 0)">
   <g dp:id="Content" xmlns:dp="http://dreampark.se/extensions" width="375" height="624" id="MainMenuViewMainMenu_DynamicChild3Content" _shadowId="MainMenuViewMainMenu_DynamicChild3Content">
      <g transform="translate(0,0)" x="0" y="0" clip-path="url(#clipPath59)">
         <g display="block" transform=" translate(0,208)">
            <g id="RootMenuItem" width="376" height="50" display="block" buffered-rendering="static" transform="translate(0,0)">
               <g id="RootMenuItemIconHolder" transform="translate(25,2)" display="none">
                  <image id="RootMenuItemIcon" opacity="1.0" width="40" height="40" display="block"/>
               </g>
               <foreignObject width="260" height="30" x="65" y="10" transform="null">
                  <body xmlns="http://www.w3.org/1999/xhtml">
                     <div xmlns="http://www.w3.org/1999/xhtml" style="font-size:22;color:#AAACAE" id="RootMenuItemText" original_x="null" fill="#AAACAE" font-size="22" width="298">Text 2</div>
                  </body>
               </foreignObject>
            </g>
            <g id="RootMenuItem" width="376" height="50" display="block" buffered-rendering="static" transform="translate(0,52)">
               <g id="RootMenuItemIconHolder" transform="translate(25,2)" display="block">
                  <image id="RootMenuItemIcon" opacity="1.0" width="40" height="40" display="block"/>
               </g>
               <foreignObject width="260" height="30" x="65" y="10" transform="null">
                  <body xmlns="http://www.w3.org/1999/xhtml">
                     <div xmlns="http://www.w3.org/1999/xhtml" style="font-size:22;color:#AAACAE" id="RootMenuItemText" original_x="null" fill="#1D212D" font-size="22" width="298">Text 1</div>
                  </body>
               </foreignObject>
            </g>
         </g>
      </g>
   </g>
</g>

我想定位元素,id="RootMenuItemText"但我需要这个元素是一个元素的子元素,该元素跟随一个元素的兄弟元素(即id"RootMenuItem",该元素的子元素具有属性中id="RootMenuItemIconHolder""block""display"

我需要定位的元素是:

<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:22;color:#AAACAE" id="RootMenuItemText" original_x="null" fill="#1D212D" font-size="22" width="298">Text 1</div>

我试过这个 Xpath:

//*[@id="RootMenuItemIconHolder"][@display='block']/following-sibling::*[last()]

但它没有定位元素。有谁知道哪个 Xpath 表达式可以帮助我定位元素?提前致谢。

4

1 回答 1

1

尝试以下操作:

//*[@id="RootMenuItemIconHolder"][@display='block']/following-sibling::*[last()]/descendant::div[@id='RootMenuItemText']

您还应该记住,您必须设置适当的名称空间才能使选择生效。xmlns这是因为您的文档在文档的不同级别上使用了默认的xml 命名空间。

于 2013-09-27T16:36:10.037 回答