在无头Chrome Docker中获取运行硒的空页面 [英] Getting empty page running selenium in headless chrome Docker

查看:87
本文介绍了在无头Chrome Docker中获取运行硒的空页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于Oracle Linux的Docker中以无头chrome运行测试用例.

我请求的页面应该重定向到带有用户名密码字段的身份验证页面,但是我在docker server()中得到了空白页面.从我的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:ERROR:bus.cc(393)]无法连接到总线:无法连接到套接字/run/dbus/system_bus_socket:没有这样的文件或目录

** [0108/134327.972921:ERROR: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 PST 2020 x86_64 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,like Gecko)Chrome/87.0.4280.88Safari/537.36".我应该使用Linux用户代理吗?

Chrome二进制文件和Chrome网络驱动程序版本:87.0.4280.88这可能是什么原因,我在过去的2天中一直处于这种状态.预先感谢.

Docker文件如下

  FROM base_imageARG USER = usr运行yum -y install wget \&&wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm \&&yum -y安装libappindicator-gtk3-12.10.0-13.el7.x86_64 \&&yum -y安装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 \&&百胜清理所有运行rm -rf/var/cache/yum;展览8080 

解决方案

因此,肯定是您的docker映像中的问题.安装过程中发生了很多事情,我看不到最明显的是安装实际的 chromedriver .

 #安装chromedriver运行apt-get install -yqq解压缩运行wget -O/tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip运行解压缩/tmp/chromedriver.zip chromedriver -d/usr/local/bin/ 

有关自定义docker映像的更多信息,您可以在答案和主题中进行检查.此外,我建议使用预构建的 Selenium docker映像,它对我来说每次都工作得很好./p>

I am running a test cases in headless chrome inside an Oracle Linux based Docker.

The page I request should get redirected to an authentication page with the username password field, but I am getting blank page in the docker server(). This works fine from my macbook.

This is the output when i try do run the same directly using chrome browser from inside docker

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:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory

**[0108/134327.972921:ERROR:cert_issuer_source_aia.cc(104)] AiaRequest::OnFetchCompleted got error -3

**

OS Details : Linux 7e3f36f795d9 4.1.12-124.45.6.el7uek.x86_64 #2 SMP Wed Nov 25 06:46:51 PST 2020 x86_64 x86_64 x86_64 GNU/Linux

Even though I am running in linux docker, user agent passed is "--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36". Should I use a Linux user agent?

Chrome binary and Chrome webdriver version : 87.0.4280.88 What could be the reason for this, I am stuck in this for last 2 days. Thanks in Advance.

Docker file is as below

        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

解决方案

So the problem in your docker image for sure. There are many thing happening in install and I don't see most obvious one with install of actual 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/

More information about custom docker image you can check in this answer and thread. Furthermore I would suggest to go with prebuilt Selenium docker image which works perfectly every time for me.

这篇关于在无头Chrome Docker中获取运行硒的空页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆