snap でインストールされている ubuntu の firefox
今週書いた記事でも言及しましたが snap でインストールされていると、Profileの場所も違うのですが、そもそも TMPDIRの設定が selenium/geckodriver で食い違ってくるということが判明したので書いておきます。
profileが作れない??
Selenium は 自動化ということもあり、通常はゲストに準じた起動状態です。個人のアカウントに紐付けるような設定は出来るのですが、認証テストに失敗しすぎてaka-BAN状態にされると個人的には苦労しますので、テストアカウントを作るくらいなら「匿名ログイン」即時profileによるテストになります。
TMPDIR を設定・定義しよう
-
github で:
https://github.com/mozilla/geckodriver/issues/2010 -
stackoverflow :
https://stackoverflow.com/questions/72092807/selenium4-and-snap-install-of-firefox-with-geckodriver-v31-times-out -
暫定: "~/tmp" 作って、TMPDIR環境変数を設定する
で解決するようです。
ProfileManager なしにはやっぱり動かない・・・
import tempfile
from selenium import webdriver
# Set the path to the GeckoDriver executable
custom_gecko_path = '/snap/bin/geckodriver'
# Set the path using the executable_path argument in FirefoxOptions
custom_profile_path = tempfile.mkdtemp(prefix="selenium_custom_profile_")
いろいろ動かないというので、上のようなサンプルコードを探してきましたが、
selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable
- snap での PATH は定義すればいい。
firefox_bin = "/snap/firefox/current/usr/lib/firefox/firefox"
firefoxdriver_bin = "/snap/firefox/current/usr/lib/firefox/geckodriver"
from: https://github.com/SeleniumHQ/selenium/issues/13252#issuecomment-1845021270
本日のハンティング終了
- これ以外の定形業務は適当にこなれて・・・