在 dockerfile 中设置 chromeoptions 语言和设置区域设置在容器中不起作用

问题描述 投票:0回答:1

我想将docker容器中的浏览器语言设置为德语。

我在 chrome 选项中设置语言是这样的。当我使用 VS 测试资源管理器在 docker 外部执行测试时,这是有效的:

ChromeOptions options = new();
options.AddArguments("--incognito");
options.AddArguments("--ignore-ssl-errors=yes");
options.AddArguments("--ignore-certificate-errors");
options.AddArguments("--disable-gpu");
options.AddArguments("--disable-infobars");
options.AddArguments("--window-size=1920,1080");
options.AddArguments("--lang=de_DE");

我还尝试在 dockerfile 中设置区域设置:

ENV TZ="Europe/Vienna"
# Install locales package
RUN apt-get update && apt-get install -y locales

# Set the locale to German
RUN sed -i -e 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/' /etc/locale.gen && \
    dpkg-reconfigure --frontend=noninteractive locales && \
    update-locale LANG=de_DE.UTF-8

# Set environment variables
ENV LANG de_DE.UTF-8  
ENV LANGUAGE de_DE:de  
ENV LC_ALL de_DE.UTF-8  

# Optionally, you might need to regenerate the locales
RUN locale-gen de_DE.UTF-8

但是浏览器启动时仍然是英文。我找不到任何其他解决方案,希望我能在这里获得帮助。 我也不明白为什么当我添加参数时,chrome 选项没有将容器中的 chrome 浏览器设置为德语。

docker-compose dockerfile selenium-chromedriver
1个回答
0
投票

我发现问题了。

如果使用

selenium.hub
容器,则还必须在 docker-compose 文件中设置语言/区域设置,因为容器默认情况下始终将环境变量设置为 en-EN。

当容器运行时,我检查了容器的详细信息,如下所示:

之后我将这些 ENV 变量添加到 docker-compose 文件中并且它起作用了:

© www.soinside.com 2019 - 2024. All rights reserved.