我有一个场景,我应该只选择颜色不是rgb(170,170,170)的那些元素。
我试图使用以下xpath找到元素:
.//span[@class='box' and not(@style='background-color: rgb(170, 170, 170)')]
使用此xpath firebug正在选择所有元素,包括我用not()限制的元素。
答案 0 :(得分:2)
最有可能(正如kjhughes指出的那样)你的样式属性包含的样式多于background-color
。要以任何方式查找您的价值,您可以使用contains()
。
(contains(@style,, 'background-color: rgb( 170, 170, 170)')
但是现在格式化仍然可能有不同的空间。
为避免它们,您可以使用translate()
删除所有空格:
translate(@style,' ','')
因此请尝试:
//span[@class='box' and not(contains(translate(@style,' ',''), 'background-color:rgb(170,170,170)') )]