2010-07-13 41 views
-1

作爲標題的問題。硒如何驗證字符字體?

+0

例如:回答你的問題]在大膽頁。與硒如何驗證它是粗體??? – 2010-07-13 06:36:19

+0

css定位器?誰可以幫助我? – 2010-07-13 07:30:55

+0

沒有人可以給我一個好主意? – 2010-07-14 01:45:46

回答

3

你應該得到「font-weight」CSS屬性的值。在IE中,大膽的值是「700」,而在Firefox中它將是「大膽的」。

您需要獲取元素的計算樣式(FF)或當前樣式(IE)。

所以對於IE則需要執行以下(這是在Java中):

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

對於火狐:

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); 
+0

爲了獲得其他字體屬性,使用「font-family」,「font-size」,「font-style」,「font-variant」 – 2010-07-15 08:50:19

+0

感謝您的幫助,這對我非常有用。 – 2010-07-21 06:45:05

+0

也許你可以將答案標記爲已接受? :) – 2010-07-21 08:08:23