selenium如何验证字符字体? [英] selenium how to verify character font?

查看:990
本文介绍了selenium如何验证字符字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为标题的问题。

推荐答案

您应该获取font-weightCSS属性的值。在IE中,粗体值为700,而在Firefox中它为粗体。

You should get the value of "font-weight" CSS property. In IE the bold value is "700" while in Firefox it will be "bold".

您需要获取计算的样式(FF)的元素。

You need to get the computed style (FF) or current style (IE) of the element.

所以对于IE你需要执行以下(它是在Java):

So for IE you will need to execute the following (it is in Java):

String strBold = selenium.getEval("var el = this.browserbot.findElement(<locator>);bold = el.currentStyle.fontWeight;");
boolean bold = "700".equals(strBold);

对于Firefox:

String strBold = selenium.getEval("var el = this.browserbot.findElement(<locator>);bold = window.document.defaultView.getComputedStyle(el,null).getPropertyValue('font-weight');");
boolean bold = "bold".equals(strBold);

这篇关于selenium如何验证字符字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆