我正在基于Oracle Linux的Docker中使用headless chrome运行一个测试用例。
我请求的页面应该被重定向到一个带有用户名密码字段的身份验证页面,但我在dockerserver((中得到了一个空白页面。这在我的macbook上运行良好。
这是我尝试从docker 内部直接使用chrome浏览器运行相同程序时的输出
bash-4.2# google-chrome --headless --no-sandbox --dump-dom --ignore-ssl-errors --ignore-certificate-errors --ssl-protocol=TLSv1 --allow-running-insecure-content --allow-insecure-localhost https://example.com/
[0108/134257.881648:错误:bus.cc(393(]无法连接到总线:无法连接到套接字/run/dbus/system_bus_socket:没有这样的文件或目录
**[0108/134327.972921:错误:cert_issuer_source_aia.cc(104(]AiaRequest::OnFetchCompleted得到错误-3
**操作系统详细信息:Linux 7e3f36f795d9 4.1.12-124.45.6.el7uek.x86_64#2 SMP 11月25日星期三太平洋标准时间06:46:51 2020 x86_64 x86_64 GNU/Linux
尽管我在linux docker中运行,但传递的用户代理是"--user agent=Mozilla/5.0(Macintosh;Intel Mac OS X 10_15_2(AppleWebKit/537.36(KHTML,类似Gecko(Chrome/87.042808.88 Safari/537.36〃;。我应该使用Linux用户代理吗?
Chrome二进制和Chrome网络驱动程序版本:87.0.4280.88这可能是什么原因,我在过去的两天里一直被困在这里。提前感谢。
Docker文件如下
FROM base_image
ARG USER=usr
RUN yum -y install wget
&& wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
&& yum -y install libappindicator-gtk3-12.10.0-13.el7.x86_64
&& yum -y install libXScrnSaver-1.2.2-6.1.el7.x86_64
&& yum -y install liberation-fonts-1.07.2-16.el7.noarch
&& yum -y install liberation-narrow-fonts-1.07.2-16.el7.noarch alsa-lib-1.1.8-1.el7.i686 xdg-utils alsa-lib-devel
&& wget http://mirror.centos.org/centos/7/os/x86_64/Packages/vulkan-filesystem-1.1.97.0-1.el7.noarch.rpm
&& wget http://mirror.centos.org/centos/7/os/x86_64/Packages/vulkan-1.1.97.0-1.el7.x86_64.rpm
&& rpm -ivh vulkan-filesystem-1.1.97.0-1.el7.noarch.rpm
&& rpm -ivh vulkan-1.1.97.0-1.el7.x86_64.rpm
&& rpm -ivh google-chrome-stable_current_x86_64.rpm
&& yum clean all
RUN rm -rf /var/cache/yum;
EXPOSE 8080
所以docker映像中的问题是肯定的。安装过程中发生了很多事情,我看不到最明显的是安装实际的chromedriver
。
# install chromedriver
RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
有关自定义docker图像的更多信息,您可以在这个答案和线程中查看。此外,我建议使用预构建的Selenium docker图像,它每次都非常适合我