下午好!
要通過 Selenium 在 Firefox 瀏覽器中檢查 getbootstrap.com 上 CSS 元素的字體大小,我使用以下腳本:
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Selenium::Firefox;
my $url = 'http://getbootstrap.com';
my $driver = Selenium::Firefox->new();
$driver->get($url);
my $elt = $driver->find_element(
'h1.mb-3.fw-semibold', 'css');
is $elt->get_css_attribute('font-size'), '72px',
'Masthead font size is unchanged';
$driver->quit();
done_testing;
當腳本運行時,測驗失敗:
? ./selenium_properties_css_attribute.pl
not ok 1 - Masthead font size is unchanged
# Failed test 'Masthead font size is unchanged'
# at ./selenium_properties_css_attribute.pl line 12.
# got: '64px'
# expected: '72px'
1..1
Killing Driver PID 4132 listening on port 45685...
# Looks like you failed 1 test of 1.
你能告訴我為什么測驗失敗了嗎?在 Firefox 瀏覽器的 getbootstrap.com 頁面上,在元素 h1.mb-3.fw-semibold 的 Computed 選項卡中,我們看到字體大小為 72px,但當我們運行測驗時,我們得到 64px。為什么?
顯示字體大小的螢屏截圖為 72px:

uj5u.com熱心網友回復:
標題的 CSS 包括:
.bd-masthead h1 {
font-size: calc(1.525rem 3.3vw);
}
因此,字體大小取決于視口的寬度。您沒有明確控制 Firefox 瀏覽器視口的寬度。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/521570.html
標籤:css硒perl
下一篇:如何在perl腳本中讀取貨幣符號
