Selenium 远程独立服务器 – 驱动程序未知

huangapple 未分类评论47阅读模式
英文:

Selenium Remote Standalone Server - Driver unknown

问题

以下是翻译好的内容:

我在Google Cloud Platform Run中有一个Docker容器,其中包含了Firefox、Gecko以及Selenium Standalone Server Jar文件版本4.0.0-alpha-1。使用这些,我有以下镜像:

FROM ubuntu:bionic
LABEL maintainer="Matheus Carvalho Gomes Moreira, matheus@hrestart.com.br"
EXPOSE 4444
ENV PORT 4444
ENV VERSION "V6.1"

# 系统更新
RUN apt-get update && apt-get install -y \
    python3 python3-pip \
    fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
    libnspr4 libnss3 lsb-release xdg-utils libxss1 libdbus-glib-1-2 \
    curl unzip wget \
    xvfb

# 安装Java和selenium-server-standalone
RUN apt-get install openjdk-8-jdk -y
RUN wget -O /home/selenium-standalone.jar http://selenium-release.storage.googleapis.com/4.0/selenium-server-standalone-4.0.0-alpha-1.jar

# 设置Java环境
RUN export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
RUN export PATH=$PATH:$JAVA_HOME/bin

# 安装geckodriver和firefox
RUN GECKODRIVER_VERSION=$(curl https://github.com/mozilla/geckodriver/releases/latest | grep -Po 'v[0-9]+.[0-9]+.[0-9]+') && \
    wget https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz && \
    tar -zxf geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz -C /usr/local/bin && \
    chmod +x /usr/local/bin/geckodriver && \
    rm geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz

RUN FIREFOX_SETUP=firefox-setup.tar.bz2 && \
    apt-get purge firefox && \
    wget -O $FIREFOX_SETUP "https://download.mozilla.org/?product=firefox-latest&os=linux64" && \
    tar xjf $FIREFOX_SETUP -C /opt/ && \
    ln -s /opt/firefox/firefox /usr/bin/firefox && \
    rm $FIREFOX_SETUP

CMD tail -f /dev/null
CMD DISPLAY=:1 xvfb-run java -jar /home/selenium-standalone.jar

我的客户端代码如下:

FirefoxOptions options = new FirefoxOptions();
driver = new RemoteWebDriver(new URL("${URL_TO_CONTAINER}"), options);

但是当我尝试创建远程驱动程序的实例以访问端点时,会出现以下错误:

无法创建新的服务:GeckoDriverService
构建信息:版本:'4.0.0-alpha-1',修订版:'d1d3728cae',时间:'2019-04-24T16:15:24'
系统信息:主机:'localhost',IP:'127.0.0.1',操作系统名称:'Linux',操作系统架构:'amd64',操作系统版本:'4.4.0',Java版本:'1.8.0_242'
驱动程序信息:驱动程序版本:unknown

我查找了一下,可能是因为它无法找到已安装的Firefox和Gecko来初始化该服务。有人有任何想法吗?

英文:

I have a docker container in Google Cloud Platform Run with Firefox, Gecko and the Selenium Standalone Server Jar file version 4.0.0-alpha-1. With this i have this image:

FROM ubuntu:bionic
LABEL maintainer="Matheus Carvalho Gomes Moreira, matheus@hrestart.com.br"
EXPOSE 4444
ENV PORT 4444
ENV VERSION "V6.1"

# Systems update
RUN apt-get update && apt-get install -y \
    python3 python3-pip \
    fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
    libnspr4 libnss3 lsb-release xdg-utils libxss1 libdbus-glib-1-2 \
    curl unzip wget \
    xvfb

# install java and selenium-server-standalone

RUN apt-get install openjdk-8-jdk -y
RUN wget -O /home/selenium-standalone.jar http://selenium-release.storage.googleapis.com/4.0/selenium-server-standalone-4.0.0-alpha-1.jar

# setup Java Environment

RUN export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
RUN export PATH=$PATH:$JAVA_HOME/bin

# install geckodriver and firefox

RUN GECKODRIVER_VERSION=`curl https://github.com/mozilla/geckodriver/releases/latest | grep -Po 'v[0-9]+.[0-9]+.[0-9]+'` && \
    wget https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz && \
    tar -zxf geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz -C /usr/local/bin && \
    chmod +x /usr/local/bin/geckodriver && \
    rm geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz

RUN FIREFOX_SETUP=firefox-setup.tar.bz2 && \
    apt-get purge firefox && \
    wget -O $FIREFOX_SETUP "https://download.mozilla.org/?product=firefox-latest&os=linux64" && \
    tar xjf $FIREFOX_SETUP -C /opt/ && \
    ln -s /opt/firefox/firefox /usr/bin/firefox && \
    rm $FIREFOX_SETUP

CMD tail -f /dev/null
CMD DISPLAY=:1 xvfb-run java -jar /home/selenium-standalone.jar

And my client:

FirefoxOptions options = new FirefoxOptions();
driver = new RemoteWebDriver(new URL("${URL_TO_CONTAINER}"), options);

But when i try to create a instance of the remote driver accesing the endpoint, it gives this error:

Unable to create new service: GeckoDriverService
Build info: version: '4.0.0-alpha-1', revision: 'd1d3728cae', time: '2019-04-24T16:15:24'
System info: host: 'localhost', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0', java.version: '1.8.0_242'
Driver info: driver.version: unknown

I searched it out and probably it´s because it can´t find Firefox and Gecko installed to initialize the service. Anyone has any thoughts?

答案1

得分: 0

我没有使用过geckodrivers,但我找到了这个项目,你可以将其用作测试,然后从代码中找出如何设置驱动程序,接下来的文章介绍了如何在Docker容器中设置使用selenium的Python应用程序。

英文:

I haven't worked with geckodrivers, but I found this project, which you can use as test and then figure out on the code how to set up the drivers and the next article to how to set up the application with selenium in a docker container.

huangapple
  • 本文由 发表于 2020年4月7日 02:33:11
  • 转载请务必保留本文链接:https://java.coder-hub.com/61066575.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定