[FIX] script selenium: web login support firefox snap

This commit is contained in:
Mathieu Benoit 2024-02-06 23:27:34 -05:00
parent 4340f1e088
commit 2dcfbf2943
2 changed files with 36 additions and 1 deletions

View file

@ -1,3 +1,7 @@
wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz
tar xvf geckodriver-v0.34.0-linux64.tar.gz
sudo mv ./.venv/geckodriver /usr/bin/geckdriver
sudo apt install libcairo2-dev python3-dev pkg-config libxt-dev libgirepository1.0-dev
pip install pycairo PyGObject

View file

@ -10,6 +10,8 @@ from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.firefox.service import Service
from subprocess import getoutput
def get_config():
@ -55,6 +57,14 @@ def get_config():
" like it!"
),
)
parser.add_argument(
"--firefox_binary_path",
help="Can specify firefox path to open selenium.",
)
parser.add_argument(
"--gecko_binary_path",
help="Can specify firefox path to open selenium.",
)
parser.add_argument(
"--url",
default="http://127.0.0.1:8069",
@ -109,9 +119,30 @@ def run(config):
firefox_options.set_preference(
"permissions.default.desktop-notification", 1
)
firefox_services = None
if config.firefox_binary_path:
firefox_services = Service(executable_path=config.firefox_binary_path)
if config.gecko_binary_path:
firefox_options.binary_location = config.gecko_binary_path
# Créez une instance du navigateur Firefox avec les options de navigation privée
driver = webdriver.Firefox(options=firefox_options)
try:
driver = webdriver.Firefox(
options=firefox_options, service=firefox_services
)
except Exception:
print("Cannot open Firefox profile, so will force firefox snap for Ubuntu users.")
firefox_services = Service(
executable_path=getoutput(
"find /snap/firefox -name geckodriver"
).split("\n")[-1]
)
firefox_options.binary_location = getoutput(
"find /snap/firefox -name firefox"
).split("\n")[-1]
driver = webdriver.Firefox(
options=firefox_options, service=firefox_services
)
# Ajout de l'enregistrement
if config.record_mode: