linux服务器执行selenium时报错,WebDriverException: Service chromedriver unexpectedly exited. Status code was: 127

一、背景

最近更换了服务器,在使用selenium执行UI自动化时,报chromedriver驱动错误,WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127。这是因为缺少 chromedriver依赖,服务器环境: ubuntu20

查看 chromedriver 需要的依赖:

./chromedriver --version

错误提示:

chromedriver: error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory
或者
chromedriver: error while loading shared libraries: libxcb.so.1: cannot open shared object file: No such file or directory

二、下载驱动

下载chromedriver:

https://registry.npmmirror.com/binary.html?path=chromedriver/

解压:

unzip chromedriver_linux64.zip

然后将解压的chromedriver移动到 /usr/bin目录下:

mv chromedriver /usr/bin/

给与执行权限:

chmod +x /usr/bin/chromedriver

检查chromedriver版本:

chromedriver -version

三、安装依赖

1、error : libgconf-2.so.4

在Ubuntu和Debian系统中,可以使用以下命令安装该库:

sudo apt-get install libgconf-2-4

在CentOS和Red Hat系统中,可以使用以下命令安装该库:

sudo yum install GConf2

安装完成后,再次启动ChromeDriver即可正常工作。如果问题仍然存在,请确保将gconf库添加到Linux系统的库路径中。可以使用以下命令将库路径添加到系统的环境变量中:

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

请注意,上述命令中的/usr/local/lib应该替换为实际的gconf库所在目录。

2、error : libxcb.so.1

在Ubuntu和Debian系统中,可以使用以下命令安装该库:

sudo apt-get install libxcb1

在CentOS和Red Hat系统中,可以使用以下命令安装该库:

sudo yum install libxcb

如果问题仍然存在,可能是由于libxcb库不在系统的默认库路径中。可以使用以下命令将库路径添加到系统的环境变量中(仅适用于bash shell):

bashCopy Codeexport LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

请注意,上述命令中的/usr/local/lib应替换为实际的libxcb库所在目录。

四、附件

1、镜像地址:https://registry.npmmirror.com/binary.html?path=chromedriver/
2、官方地址:https://googlechromelabs.github.io/chrome-for-testing/#stable

posted @ 2023-10-30 14:15  xyztank  阅读(328)  评论(0编辑  收藏  举报