Solution to change the text in selenium screenshot into square boxes in Linux

I. Introduction

When I took a screenshot using selenium in Linux recently, I found that the text had changed into boxes:

Insert image description here
Although it does not affect the use of selenium, it does affect debugging and is not good-looking. Later I found out that it was because Linux lacks Chinese fonts, and it can be solved by installing Chinese fonts.

2. Install Chinese fonts (take centos as an example)

1) Pre-inspection

First check /usr/sharewhether there is a directory in the directory fonts. fontconfigIf not, you need to execute the following command to install it:

yum -y install fontconfig

After the installation is complete, you can use fc-listthe command to check the fonts installed on the system:
Insert image description here
Here we can directly use fc-list :lang=zhthe command to check whether the Chinese fonts are installed.

2) Download the Songti font

There are many on the Internet, just search for the Song Dynasty font and you will be able to find them. If you really can’t find the card at the end of the article, please contact me and I will send it to you (links are easy to be blocked).

3) Install fonts

Directory to enter first /usr/share/fonts:

cd /usr/share/fonts

Then /usr/shared/fontscreate a new Chinese font folder in and enter the command:

mkdir chinese

Then transfer the downloaded fonts chineseto the directory.

Execute the command again to install the font index command:

yum install mkfontscale

Then enter the chinese directory and execute the command to generate the font index:

cd chinese
mkfontscale

fc-list :lang=zhFinally , you can see the installed Chinese fonts through the command:
Insert image description here
At this time, if we take a screenshot, it will display normally, and the box fonts will no longer appear.

Guess you like

Origin blog.csdn.net/momoda118/article/details/132421263