当前位置: 首页 > 工具软件 > Firefox Home > 使用案例 >

Selenium+Firefox在Ubuntu22.04上不工作

阎京
2023-12-01

原因:Ubuntu22.04上默认使用snap的Firefox,如果设置使得firefox在sandbox运行时无法访问系统/tmp目录,会造成geckodriver驱动Firefox失败。

Github原文如下

Firefox running in Linux Sandbox (e.g. Snap package):

Using geckodriver to launch Firefox inside a sandbox – for example
a Firefox distribution using Snap or Flatpak – can fail with a
“Profile not found” error if the sandbox restricts Firefox’s ability
to access the system temporary directory. geckodriver uses the
temporary directory to store Firefox profiles created during the run.

This issue can be worked around by setting the TMPDIR environment
variable to a location that both Firefox and geckodriver have
read/write access to e.g.:

% mkdir $HOME/tmp
% TMPDIR=$HOME/tmp geckodriver

Alternatively, geckodriver may be used with a Firefox install that
is not packaged inside a sandboxed e.g. from mozilla.org.

 类似资料: