如何在xml中找到xpath具有命名空间的节点

时间:2016-04-01 18:07:27

标签: selenium xpath

我正在尝试为selenium找到带有Xpath的div节点。这里div有类别/账户&需要选择作为ext:tree-node-id值的联系人,但是作为ext:tree-node-id是一个命名空间,我的xpath下面不起作用。

    //li[@class='x-tree-node']//div[contains(.,ext:tree-node-id='categories\/Accounts & Contacts')]
//li[@class='x-tree-node']//div[@ext:tree-node-id='categories\/Accounts & Contacts']


 <li class="x-tree-node">
<div class="x-tree-node-el x-unselectable folder x-tree-node-collapsed" unselectable="on" ext:tree-node-id="categories\/Accounts & Contacts">
<span class="x-tree-node-indent"/>
<img class="x-tree-ec-icon x-tree-elbow-plus" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt=""/>
<img class="x-tree-node-icon" unselectable="on" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt=""/>
<a class="x-tree-node-anchor" tabindex="1" href="" hidefocus="on">
</div>
<ul class="x-tree-node-ct" style="display: none;">
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-unselectable folder x-tree-node-collapsed" unselectable="on" ext:tree-node-id="categories\/Opportunities">
<span class="x-tree-node-indent"/>
<img class="x-tree-ec-icon x-tree-elbow-plus" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt=""/>
<img class="x-tree-node-icon" unselectable="on" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt=""/>
<a class="x-tree-node-anchor" tabindex="1" href="" hidefocus="on">
</div>
<ul class="x-tree-node-ct" style="display: none;">
</li>

1 个答案:

答案 0 :(得分:1)

属性中的冒号不允许xpath工作。你需要改进一点,它可以按你的意愿工作,如:

//li[@class='x-tree-node']//div[@*[contains(local-name(), tree-node-id)] = 'categories\\/Accounts & Contacts']

&#34;本地名称&#34;将在名为&#34; tree-node-id&#34;。

的冒号后面选择名称