我正在尝试自动化手动脚本(在Java中使用硒)来检查网页上某个字段(标签:代表必填字段)的粗体外观。可能是什么硒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"));
Run Code Online (Sandbox Code Playgroud)
使用Selenium RC时,请参见此技术,只需使用即可font-weight
(或fontWeight
根据用法)。
您可以使用该方法检查字体粗细style()
(假设您实际上使用的是 Selenium-Webdriver)。
假设你有这样的 HTML:
<body>
<div id='1' style='font-weight:normal'>
<div id='2' style='font-weight:bold'>Field Label</div>
<div id='3'>Field</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
您可以执行以下操作来检查字段标签 div 的字体粗细(以下是在 Ruby 中进行的,尽管在其他语言中也应该可以实现类似的操作)。
el = driver.find_element(:id, "2")
if el.style('font-weight') >= 700
puts 'text is bold'
else
puts 'text is not bold'
end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11144 次 |
最近记录: |