【问题标题】:Selenium Only local connections allowed and NoSuchSessionExceptionSelenium 仅允许本地连接和 NoSuchSessionException
【发布时间】:2017-07-05 17:55:02
【问题描述】:

我有以下 docker-container

FROM ubuntu:xenial
MAINTAINER Hasan Kara

RUN set -xe \
 \
# Install Java, Chrome, Xvfb, and unzip
 && apt-get update \
 && apt-get install -y \
      openjdk-8-jre \
      chromium-browser \
      xvfb \
      curl \
      wget \
      unzip \

 && rm -rf /var/lib/apt/lists/* \ 
 && ln -s /usr/lib/chromium-browser/chromium-browser /usr/bin/google-chrome \
 \
# Download and install chrome drive and selenium server standalone
 && wget -q "https://chromedriver.storage.googleapis.com/2.27/chromedriver_linux64.zip" \
 && wget -q "http://selenium-release.storage.googleapis.com/3.0/selenium-server-standalone-3.0.1.jar" \

 && unzip chromedriver_linux64.zip \
 && mv chromedriver /usr/local/bin \
 && mv selenium-server-standalone-3.0.1.jar /usr/local/bin

VOLUME /downloads

ENV DISPLAY :10

CMD export DISPLAY=:10 && Xvfb :10 -screen 0 1366x768x24 -ac & google-chrome --no-sandbox -remote-debugging-port=9222 & java -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar &

EXPOSE 4444 9222

我运行的是:

docker run --rm -it --shm-size=512m --name chromium -p 4444:4444 -p 9222:9222 hasankarafhnw/seleniumchromium /bin/bash

在 bash 中我手动运行,因为由于某种原因 CMD 不起作用...

export DISPLAY=:10 && Xvfb :10 -screen 0 1366x768x24 -ac & google-chrome --no-sandbox -remote-debugging-port=9222 & java -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar &

现在我可以通过“http://192.168.99.100:4444/wd/hub/static/resource/hub.html”完美连接到 selenium hub,但如果尝试:

  • 通过集线器创建会话
  • 使用this code容器中创建一个会话。
  • 通过在主机操作系统上运行的 RemoteWebDriver 创建一个会话。

我收到以下错误:

只允许本地连接。 信息 - 尝试双语
会话,假设 Postel 定律在远端成立

INFO - 正在执行:[截取屏幕截图])警告 - 抛出异常 org.openqa.selenium.NoSuchSessionException:没有这样的会话

Chrome 驱动程序:2.27.440175
铬:55.0.2883.87
Selenium 服务器独立:3.0.1 码头工人:1.13
主机操作系统:Win 7

远程驱动代码:

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("./extension_0_2_0_10.crx"));

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

WebDriver driver = new RemoteWebDriver(new URL( "http://192.168.99.100:4444/wd/hub"), capabilities);
driver = new Augmenter().augment(driver);
driver.get("http://google.com");

【问题讨论】:

标签: selenium docker virtual-machine selenium-chromedriver chromium


【解决方案1】:

您需要为 chromedriver 可执行文件(不是 chrome!)设置 whitelisted-ips 参数。您可以在节点启动时通过设置系统属性webdriver.chrome.whitelistedIps 来实现它,就像在您的命令中一样:

CMD export DISPLAY=:10 && Xvfb :10 -screen 0 1366x768x24 -ac & google-chrome --no-sandbox -remote-debugging-port=9222 & java -Dwebdriver.chrome.whitelistedIps= -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar &

【讨论】:

    猜你喜欢
    • 2019-01-03
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多