Chinaunix首页 | 论坛 | 博客
  • 博客访问: 174991
  • 博文数量: 15
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 375
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-06 20:00
文章分类

全部博文(15)

文章存档

2009年(2)

2008年(13)

我的朋友

分类: Python/Ruby

2008-10-22 21:52:10

selenium访问块元素的样式属性
selenium在ui测试中应用很普遍,对简单的website界面墨盒测试使用记录和回放就能满足要求了,但对一些较复杂的操作比较和验证就相对较难些。因为中文资料不多,英文资料也比较抽象。所以使用它来测试要看的东西也很多。
  这次主要遇到一个问题,让验证当前选中的div块背景为blue.
  
xxx

  
   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中使用复合值的话,要分开来取值。
继续上面的例子。
  
  
   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')}

品蓝
阅读(7045) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~