未创建会话:此版本的ChromeDriver仅支持Chrome版本114

jaxagkaj  于 12个月前  发布在  Go
关注(0)|答案(8)|浏览(300)

我正在AWS Batch环境中从Docker容器运行Docker镜像。这一切都很好地工作了一段时间,但从今天开始,我得到了以下错误。

E   selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This 
version of ChromeDriver only supports Chrome version 114
E   Current browser version is 116.0.5845.96 with binary path /opt/google/chrome/google-chrome

安装Chrome的Dockerfile如下所示

FROM python:3.10
WORKDIR /usr/src/app
COPY . .

RUN pip install --trusted-host pypi.org --upgrade pip
RUN pip install --no-cache-dir \
--extra-index-url https://artifactory.int.csgdev01.citcosvc.com/artifactory/api/pypi/citco- 
pypi/simple \
-r requirements.txt

RUN pip install awscli

RUN apt-get install -yqq unzip curl
RUN apt-get -y update
RUN apt-get install zip -y
RUN apt-get install unzip -y
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >>

/etc/apt/sources.list.d/google-chrome.list RUN apt-get -y update RUN apt-get -y install -y google-chrome-stable

# Install chrome driver
RUN wget -N https://chromedriver.storage.googleapis.com/`curl -sS 
chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip -P ~/
RUN unzip ~/chromedriver_linux64.zip -d ~/
RUN rm ~/chromedriver_linux64.zip
RUN mv -f ~/chromedriver /usr/local/bin/chromedriver
RUN chmod 0755 /usr/local/bin/chromedriver
RUN ls -lt
RUN ls -lt /usr/local/bin
RUN chmod +x ./run.sh
CMD ["bash", "./run.sh"]

我的selenium python测试类在下面

from selenium import webdriver
import unittest
class Test_SecTransferWorkflow(unittest.TestCase):
    options = webdriver.ChromeOptions()
    options.add_argument('--no-sandbox')
    options.add_argument("--enable-javascript")
    options.add_argument("--start-maximized")
    options.add_argument("--incognito")
    options.add_argument('--headless')
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--enable-features=NetworkService')
    options.add_argument('--shm-size=1g')
    options.add_argument('--disable-gpu')
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_argument("--window-size=1920,1080")
    options.add_argument("--disable-extensions")
    options.add_argument('--disable-dev-shm-usage')
    options.add_experimental_option('useAutomationExtension', False)
    options.add_experimental_option("detach", True)
    options.add_argument('--allow-running-insecure-content')
    options.add_argument('--allow-insecure-localhost')
    options.add_argument('--ignore-ssl-errors=yes')
    options.add_argument('--user-agent=Chrome/77')
    driver = webdriver.Chrome(options=options)

    @classmethod
    def setUpClass(cls):
        try:
            cls.driver.delete_all_cookies()
            cls.driver.get(TestData_common.BASE_URL)
            time.sleep(2)
        except WebDriverException as e:
            print('Site down...> ', e)
            cls.driver.delete_all_cookies()
        time.sleep(3)

    def test_001_login(self):
        if not TestData_common.URL_FOUND:
            pytest.skip('Site seems to be down...')
        self.loginPage = LoginPage(self.driver)
        self.loginPage.do_click_agree_button()
        self.driver.maximize_window()
        print('Successfully clicked on AGREE button...')
        time.sleep(2)

到目前为止,我在运行此映像时没有遇到任何问题,直到今天遇到此错误。任何帮助都非常感谢。

t1qtbnec

t1qtbnec1#

Chrome(116)和chromedriver(114)的版本不匹配。这是因为最新版本的chromedriver(如chromedriver.storage.googleapis.com/LATEST_RELEASE所述)不一定总是与debian repo中的最新版本的Chrome相匹配。虽然这些主要版本会 * 经常 * 匹配(这就是为什么这在过去对你有效),但你不能总是依赖于这种情况,正如你现在看到的。
相反,您应该检查Chrome的版本,然后安装适当版本的chromedriver。如chromedriver downloads page上所述,您可以使用他们的API endpoint查找各种版本的chromedriver的下载链接,或者在 Jmeter 板上查找链接,两者都将包含与chrome 116兼容的chromedriver下载版本的链接-例如在撰写本文时:https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip(但请注意此zip结构可能与您已经使用的下载链接不同)。
在我自己的dockerfile中,我手动指定chromedriver下载URL,然后运行一个脚本来测试主要版本是否匹配。不过,你可以使用上面提到的API端点来自动获取正确的chromedriver URL。
至于为什么chromedriver.storage.googleapis.com/LATEST_RELEASE指向主版本114而不是116,尽管有116的下载和稳定的debian版本是116,老实说,我真的不确定。

rqdpfwrv

rqdpfwrv2#

如上所述,https://chromedriver.chromium.org/downloads现在建议从https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json下载chromedriver
试试这个来获得最新的v116:

export CHROMEDRIVER_VERSION=116
export CHROMEDRIVER_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | \
  jq -r --arg version "$CHROMEDRIVER_VERSION" '[.versions[] | select(.version | startswith($version + "."))] | last | .downloads.chromedriver[] | select(.platform == "linux64").url')

(This假设JSON文件是按从旧到新排序的,所以我们需要lastversion="160.x.y.z"。)
注意,下载的.zip文件现在是一个包含chromedriver可执行文件的chromedriver-linux64文件夹。
Dockerfile中,尝试:

ARG CHROMEDRIVER_VERSION='116'

# Install Chrome WebDriver
RUN CHROMEDRIVER_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | \
  jq -r --arg version "$CHROMEDRIVER_VERSION" '[.versions[] | select(.version | startswith($version + "."))] | last | .downloads.chromedriver[] | select(.platform == "linux64").url') && \
  mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \
  curl -sS -o /tmp/chromedriver_linux64.zip "$CHROMEDRIVER_URL" && \
  unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \
  rm /tmp/chromedriver_linux64.zip && \
  chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver-linux64/chromedriver && \
  ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver-linux64/chromedriver /usr/local/bin/chromedriver

FWIW,gpt4帮助我编写了jq子句来解析JSON
https://chat.openai.com/share/ebe38666-9ea7-4bd4-9935-5430fec339f5
此外,如果您将select(.platform == "linux64")替换为以下平台之一,则可以使用以下所有其他平台:

curl -s https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | \
jq '[.versions[] | select(.version | startswith("116."))] | last | .downloads.chromedriver'

[
  {
    "platform": "linux64",
    "url": "..."
  },
  {
    "platform": "mac-arm64",
    "url": "..."
  },
  {
    "platform": "mac-x64",
    "url": "..."
  },
  {
    "platform": "win32",
    "url": "..."
  },
  {
    "platform": "win64",
    "url": "..."
  }
]
l7mqbcuq

l7mqbcuq3#

在Docker中安装最新的Chrome和Chromedriver:

# Install latest Chrome
RUN CHROME_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | jq -r '.channels.Stable.downloads.chrome[] | select(.platform == "linux64") | .url') \
    && curl -sSLf --retry 3 --output /tmp/chrome-linux64.zip "$CHROME_URL" \
    && unzip /tmp/chrome-linux64.zip -d /opt \
    && ln -s /opt/chrome-linux64/chrome /usr/local/bin/chrome \
    && rm /tmp/chrome-linux64.zip

# Install latest chromedriver
RUN CHROMEDRIVER_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | jq -r '.channels.Stable.downloads.chromedriver[] | select(.platform == "linux64") | .url') \
    && curl -sSLf --retry 3 --output /tmp/chromedriver-linux64.zip "$CHROMEDRIVER_URL" \
    && unzip -o /tmp/chromedriver-linux64.zip -d /tmp \
    && rm -rf /tmp/chromedriver-linux64.zip \
    && mv -f /tmp/chromedriver-linux64/chromedriver "/usr/local/bin/chromedriver" \
    && chmod +x "/usr/local/bin/chromedriver"

根据https://chromedriver.chromium.org/downloads/version-selection版本115,Google已经改变了Chrome和Chromedriver的发布过程。有多个JSON端点,您可以探测Chrome和Chromedriver的最新稳定版本。
这个答案的灵感来自Dr Nic的答案,除了它使用端点来获取最新(稳定)版本。

ssgvzors

ssgvzors4#

我已经修复了它,从这里降级到以前的版本:https://google-chrome.it.uptodown.com/mac/versions
然后,将这一行作为sudo添加到etc/hosts文件中:

127.0.0.1 tools.google.com

Google Chrome将无法访问URL以进行自动更新。
这可能不是最好的解决方案,但它可以完成工作。“

2g32fytz

2g32fytz5#

我的猜测是,你是在旧版本的 selenium 。Selenium版本4.10.0或以下将不支持最新版本的Chrome浏览器。

**解决方案:**将selenium版本升级到v4.11.2。这应该可以解决问题。

ylamdve6

ylamdve66#

你需要在latest_release_url中找到一个driver_version,它可以在chrome-for-testing#json-api-endpoints中找到,然后指定latest_release_url和driver_version参数。

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
...
...
options = Options()
options.add_argument("--no-sandbox")
options.add_argument('--headless=new')
options.add_argument("--disable-gpu")

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager(
            latest_release_url='https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json',
            driver_version='116.0.5845.96').install()), options=options)

在本例中,我使用last-known-good-versions-with-downloads.json;并选择版本116.0.5845.96。有时灵

wpcxdonn

wpcxdonn7#

我用Java解决了这个问题:

WebDriverManager.chromedriver().browserVersionDetectionCommand("google-chrome --version | cut -d ' ' -f 3");
ukdjmx9f

ukdjmx9f8#

我只是建议将Chrome降级到114(这在配置Jibri时对我有效)

wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_114.0.5735.198-1_amd64.deb

sudo dpkg -i google-chrome-stable_114.0.5735.198-1_amd64.deb

相关问题