我正在尝试自动化手动脚本(在 java 中使用 selenium)来检查网页上某个字段(标签:代表必填字段)的粗体外观。有什么可能的 selenium java 函数来验证某个元素的粗体外观(在类中没有关于外观的信息)
最佳答案
通过 WebDriver(在 Java 中),您可以使用 getCssValue() .
import static org.junit.Assert.assertTrue;
(...)
// assuming elem is a healthy WebElement instance, your found element
String fontWeight = elem.getCssValue("font-weight");
assertTrue(fontWeight.equals("bold") || fontWeight.equals("700"));
(since 700
is the same as bold
)
使用 Selenium RC,请参阅 this technique ,只需使用 font-weight
(或 fontWeight
,具体取决于用途)。
关于java - 如何验证 Selenium 中某个字段的大胆外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10100438/