selenium访问块元素的样式属性

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

 

selenium访问块元素的样式属性
selenium在ui测试中应用很普遍,对简单的website界面墨盒测试使用记录和回放就能满足要求了,但对一些较复杂的操作比较和验证就相对较难些。因为中文资料不多,英文资料也比较抽象。所以使用它来测试要看的东西也很多。   这次主要遇到一个问题,让验证当前选中的div块背景为blue.    <div >块的背景色为#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 >注意深红色文本,与上面有所不同,我这样试过,可用。 target:

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

相关文章:

  • 2021-05-16
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2021-06-11
  • 2021-05-20
  • 2021-06-15
猜你喜欢
  • 2022-01-26
  • 2021-08-10
  • 2022-01-11
  • 2021-07-15
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案