如何使用带有 Java 的 Selenium WebDriver 确定实际字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20683007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:34:34  来源:igfitidea点击:

How to determine actual font size using Selenium WebDriver with Java

javaselenium-webdriver

提问by user254694

If my font-size is set to be X-Large and I want to test how many pixels that is on a particular browser using Selenium WebDriver. How would I do that?

如果我的字体大小设置为 X-Large 并且我想使用 Selenium WebDriver 测试特定浏览器上有多少像素。我该怎么做?

The idea is to check if the font size falls within a particular range of allowed font-sizes for our window size.

这个想法是检查字体大小是否在我们的窗口大小允许的字体大小的特定范围内。

采纳答案by Sergio Cazzolato

A way to do that is getting the font-size from the styles, e.g.

一种方法是从样式中获取字体大小,例如

driver.findElement(By.id("xxx")).getCssValue("font-size");

And then, based on this information you could calculate the size by following this article: http://www.erinsowards.com/articles/2010/01/calculating-font-sizes.php

然后,根据这些信息,您可以按照这篇文章计算尺寸:http: //www.erinsowards.com/articles/2010/01/calculating-font-sizes.php