I am using Selenium + Chromium headless for automated testing, and the execution environment has been encapsulated into a Docker image based on Debian. Through screenshots taken during the execution, I noticed that the page is being scaled down. I set the resolution to 1920×1080, and while the page meets this resolution, the elements appear to be shrunk, with large white margins on both sides. Here is an example of a normal webpage: And here is the screenshot taken by Selenium:
My chromium variables is :
--headless
--window-size= 1920,1080
--force-device-scale-factor=1
--disable-gpu
--no-sandbox
--hide-scrollbars
--disable-dev-shm-usage
--remote-allow-origins=*
My docker file likes:
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
chromium \
libglib2.0-0 \
libnss3-dev \
libxcb1 \
locales \
openjdk-17-jre \
fontconfig \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-symbola \
fonts-noto \
fonts-freefont-ttf
Please tell me what I should do next. Thank you.
I am using Selenium + Chromium headless for automated testing, and the execution environment has been encapsulated into a Docker image based on Debian. Through screenshots taken during the execution, I noticed that the page is being scaled down. I set the resolution to 1920×1080, and while the page meets this resolution, the elements appear to be shrunk, with large white margins on both sides. Here is an example of a normal webpage: And here is the screenshot taken by Selenium:
My chromium variables is :
--headless
--window-size= 1920,1080
--force-device-scale-factor=1
--disable-gpu
--no-sandbox
--hide-scrollbars
--disable-dev-shm-usage
--remote-allow-origins=*
My docker file likes:
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
chromium \
libglib2.0-0 \
libnss3-dev \
libxcb1 \
locales \
openjdk-17-jre \
fontconfig \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-symbola \
fonts-noto \
fonts-freefont-ttf
Please tell me what I should do next. Thank you.
Share Improve this question asked Feb 14 at 5:59 linxiao yulinxiao yu 132 bronze badges 01 Answer
Reset to default 0Try this to set resolution
driver.set_window_size(1920, 1080)
driver.save_screenshot("file_name.png")