我正在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)
到目前为止,我在运行此映像时没有遇到任何问题,直到今天遇到此错误。任何帮助都非常感谢。
8条答案
按热度按时间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,老实说,我真的不确定。rqdpfwrv2#
如上所述,https://chromedriver.chromium.org/downloads现在建议从https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json下载chromedriver
试试这个来获得最新的v116:
(This假设JSON文件是按从旧到新排序的,所以我们需要
last
的version="160.x.y.z"
。)注意,下载的.zip文件现在是一个包含
chromedriver
可执行文件的chromedriver-linux64
文件夹。在
Dockerfile
中,尝试:FWIW,gpt4帮助我编写了
jq
子句来解析JSONhttps://chat.openai.com/share/ebe38666-9ea7-4bd4-9935-5430fec339f5
此外,如果您将
select(.platform == "linux64")
替换为以下平台之一,则可以使用以下所有其他平台:l7mqbcuq3#
在Docker中安装最新的Chrome和Chromedriver:
根据https://chromedriver.chromium.org/downloads/version-selection版本115,Google已经改变了Chrome和Chromedriver的发布过程。有多个JSON端点,您可以探测Chrome和Chromedriver的最新稳定版本。
这个答案的灵感来自Dr Nic的答案,除了它使用端点来获取最新(稳定)版本。
ssgvzors4#
我已经修复了它,从这里降级到以前的版本:https://google-chrome.it.uptodown.com/mac/versions
然后,将这一行作为sudo添加到etc/hosts文件中:
Google Chrome将无法访问URL以进行自动更新。
这可能不是最好的解决方案,但它可以完成工作。“
2g32fytz5#
我的猜测是,你是在旧版本的 selenium 。Selenium版本
4.10.0
或以下将不支持最新版本的Chrome浏览器。**解决方案:**将selenium版本升级到
v4.11.2
。这应该可以解决问题。ylamdve66#
你需要在latest_release_url中找到一个driver_version,它可以在chrome-for-testing#json-api-endpoints中找到,然后指定latest_release_url和driver_version参数。
在本例中,我使用last-known-good-versions-with-downloads.json;并选择版本116.0.5845.96。有时灵
wpcxdonn7#
我用Java解决了这个问题:
ukdjmx9f8#
我只是建议将Chrome降级到114(这在配置Jibri时对我有效)