Xpath基本语法

selenium访问块元素的样式属性

http://blog.chinaunix.net/uid-2311783-id-2546842.html

selenium访问块元素的样式属性
selenium在ui测试中应用很普遍,对简单的website界面墨盒测试使用记录和回放就能满足要求了,但对一些较复杂的操作比较和验证就相对较难些。因为中文资料不多,英文资料也比较抽象。所以使用它来测试要看的东西也很多。   这次主要遇到一个问题,让验证当前选中的div块背景为blue.    <div id="app-info-item" class="selected-item">xxx</div>       bases-view.css      .selected-item {         background-color: #6CA3D1;     }    要验证div id="app-info-item">块的背景色为#6CA3D1;就需要用javascript调用块的样式属性。使用方法为:insert new command:rgb(108, 163, 209)   

command:   verifyExpression target : javascript{selenium.browserbot.getCurrentWindow().getComputedStyle(this.page().findElement("xpath=//div[@id='app-info-item']"),'').getPropertyValue('background-color').toLowerCase()} value : #6CA3D1

sdfasdf
在side中执行这个command,说rgb(108, 163, 209)与#6CA3D1不同,验证失败。驱g上网,发现原来这段javascript代码在firefox中生成的颜色表示是rgb(x,y,z);在ie中是#xxxx形式。使用firefox的colorzilla插件,获取这个颜色的rgb表示。
要注意的是,如果在style中使用复合值的话,要分开来取值。 继续上面的例子。
   <div id="header"></div>       bases-view.css   #div#header{       background:#578FC0 url(/images/radar-logo.gif) no-repeat scroll 98% center;    }
  我们在selenium中要检验radar-logo.gif,  或检验#578FC0, 或其他属性,应该怎么写表达式呢?   呵呵,要写对应的属性名,   如取背景图像
url(/images/radar-logo.gif),  要使用getPropertyValue('background-image')   要取背景颜色#578FC0,   使用getPropertyValue('background-color')   以取图像为例:注意深红色文本,与上面有所不同,我这样试过,可用。 target:

javascript{selenium.browserbot.getCurrentWindow().getComputedStyle(this.page().findElement('xpath=//div[@id=\'header\']'),'').getPropertyValue('background-image')}

原文地址:https://www.cnblogs.com/qmfsun/p/3130827.html