mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 02:31:45 +01:00
remove webdriver-manager dependency
This commit is contained in:
98
pdm.lock
generated
98
pdm.lock
generated
@@ -5,7 +5,7 @@
|
|||||||
groups = ["default", "dev"]
|
groups = ["default", "dev"]
|
||||||
strategy = ["cross_platform"]
|
strategy = ["cross_platform"]
|
||||||
lock_version = "4.4.1"
|
lock_version = "4.4.1"
|
||||||
content_hash = "sha256:710d12dd05635102f9a19f332ace367f6fbc903fe2f780a1fc017aca023e0e1f"
|
content_hash = "sha256:f7f650ad486d2908bfa8253d062cb84d201ded59d0c40d9c79fa3c2d0da3b3c8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "altgraph"
|
name = "altgraph"
|
||||||
@@ -143,61 +143,6 @@ files = [
|
|||||||
{file = "cffi-1.16.0.tar.gz", hash = "sha256:bcb3ef43e58665bbda2fb198698fcae6776483e0c4a631aa5647806c25e02cc0"},
|
{file = "cffi-1.16.0.tar.gz", hash = "sha256:bcb3ef43e58665bbda2fb198698fcae6776483e0c4a631aa5647806c25e02cc0"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "charset-normalizer"
|
|
||||||
version = "3.3.2"
|
|
||||||
requires_python = ">=3.7.0"
|
|
||||||
summary = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
|
|
||||||
files = [
|
|
||||||
{file = "charset-normalizer-3.3.2.tar.gz", hash = "sha256:f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:25baf083bf6f6b341f4121c2f3c548875ee6f5339300e08be3f2b2ba1721cdd3"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:06435b539f889b1f6f4ac1758871aae42dc3a8c0e24ac9e60c2384973ad73027"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9063e24fdb1e498ab71cb7419e24622516c4a04476b17a2dab57e8baa30d6e03"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6897af51655e3691ff853668779c7bad41579facacf5fd7253b0133308cf000d"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1d3193f4a680c64b4b6a9115943538edb896edc190f0b222e73761716519268e"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:cd70574b12bb8a4d2aaa0094515df2463cb429d8536cfb6c7ce983246983e5a6"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8465322196c8b4d7ab6d1e049e4c5cb460d0394da4a27d23cc242fbf0034b6b5"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a9a8e9031d613fd2009c182b69c7b2c1ef8239a0efb1df3f7c8da66d5dd3d537"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:beb58fe5cdb101e3a055192ac291b7a21e3b7ef4f67fa1d74e331a7f2124341c"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:e06ed3eb3218bc64786f7db41917d4e686cc4856944f53d5bdf83a6884432e12"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:2e81c7b9c8979ce92ed306c249d46894776a909505d8f5a4ba55b14206e3222f"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_s390x.whl", hash = "sha256:572c3763a264ba47b3cf708a44ce965d98555f618ca42c926a9c1616d8f34269"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:fd1abc0d89e30cc4e02e4064dc67fcc51bd941eb395c502aac3ec19fab46b519"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-win32.whl", hash = "sha256:3d47fa203a7bd9c5b6cee4736ee84ca03b8ef23193c0d1ca99b5089f72645c73"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp310-cp310-win_amd64.whl", hash = "sha256:10955842570876604d404661fbccbc9c7e684caf432c09c715ec38fbae45ae09"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:802fe99cca7457642125a8a88a084cef28ff0cf9407060f7b93dca5aa25480db"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:573f6eac48f4769d667c4442081b1794f52919e7edada77495aaed9236d13a96"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:549a3a73da901d5bc3ce8d24e0600d1fa85524c10287f6004fbab87672bf3e1e"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f27273b60488abe721a075bcca6d7f3964f9f6f067c8c4c605743023d7d3944f"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1ceae2f17a9c33cb48e3263960dc5fc8005351ee19db217e9b1bb15d28c02574"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:65f6f63034100ead094b8744b3b97965785388f308a64cf8d7c34f2f2e5be0c4"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:753f10e867343b4511128c6ed8c82f7bec3bd026875576dfd88483c5c73b2fd8"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4a78b2b446bd7c934f5dcedc588903fb2f5eec172f3d29e52a9096a43722adfc"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:e537484df0d8f426ce2afb2d0f8e1c3d0b114b83f8850e5f2fbea0e797bd82ae"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:eb6904c354526e758fda7167b33005998fb68c46fbc10e013ca97f21ca5c8887"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:deb6be0ac38ece9ba87dea880e438f25ca3eddfac8b002a2ec3d9183a454e8ae"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_s390x.whl", hash = "sha256:4ab2fe47fae9e0f9dee8c04187ce5d09f48eabe611be8259444906793ab7cbce"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:80402cd6ee291dcb72644d6eac93785fe2c8b9cb30893c1af5b8fdd753b9d40f"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-win32.whl", hash = "sha256:7cd13a2e3ddeed6913a65e66e94b51d80a041145a026c27e6bb76c31a853c6ab"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp311-cp311-win_amd64.whl", hash = "sha256:663946639d296df6a2bb2aa51b60a2454ca1cb29835324c640dafb5ff2131a77"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:0b2b64d2bb6d3fb9112bafa732def486049e63de9618b5843bcdd081d8144cd8"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:ddbb2551d7e0102e7252db79ba445cdab71b26640817ab1e3e3648dad515003b"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:55086ee1064215781fff39a1af09518bc9255b50d6333f2e4c74ca09fac6a8f6"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8f4a014bc36d3c57402e2977dada34f9c12300af536839dc38c0beab8878f38a"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a10af20b82360ab00827f916a6058451b723b4e65030c5a18577c8b2de5b3389"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8d756e44e94489e49571086ef83b2bb8ce311e730092d2c34ca8f7d925cb20aa"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:90d558489962fd4918143277a773316e56c72da56ec7aa3dc3dbbe20fdfed15b"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ac7ffc7ad6d040517be39eb591cac5ff87416c2537df6ba3cba3bae290c0fed"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:7ed9e526742851e8d5cc9e6cf41427dfc6068d4f5a3bb03659444b4cabf6bc26"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:8bdb58ff7ba23002a4c5808d608e4e6c687175724f54a5dade5fa8c67b604e4d"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:6b3251890fff30ee142c44144871185dbe13b11bab478a88887a639655be1068"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_s390x.whl", hash = "sha256:b4a23f61ce87adf89be746c8a8974fe1c823c891d8f86eb218bb957c924bb143"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:efcb3f6676480691518c177e3b465bcddf57cea040302f9f4e6e191af91174d4"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-win32.whl", hash = "sha256:d965bba47ddeec8cd560687584e88cf699fd28f192ceb452d1d7ee807c5597b7"},
|
|
||||||
{file = "charset_normalizer-3.3.2-cp312-cp312-win_amd64.whl", hash = "sha256:96b02a3dc4381e5494fad39be677abcb5e6634bf7b4fa83a6dd3112607547001"},
|
|
||||||
{file = "charset_normalizer-3.3.2-py3-none-any.whl", hash = "sha256:3e4d1f6587322d2788836a99c69062fbb091331ec940e02d12d179c1d53e25fc"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colorama"
|
name = "colorama"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@@ -680,16 +625,6 @@ files = [
|
|||||||
{file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"},
|
{file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "python-dotenv"
|
|
||||||
version = "1.0.1"
|
|
||||||
requires_python = ">=3.8"
|
|
||||||
summary = "Read key-value pairs from a .env file and set them as environment variables"
|
|
||||||
files = [
|
|
||||||
{file = "python-dotenv-1.0.1.tar.gz", hash = "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca"},
|
|
||||||
{file = "python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pywin32"
|
name = "pywin32"
|
||||||
version = "306"
|
version = "306"
|
||||||
@@ -747,22 +682,6 @@ files = [
|
|||||||
{file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"},
|
{file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "requests"
|
|
||||||
version = "2.31.0"
|
|
||||||
requires_python = ">=3.7"
|
|
||||||
summary = "Python HTTP for Humans."
|
|
||||||
dependencies = [
|
|
||||||
"certifi>=2017.4.17",
|
|
||||||
"charset-normalizer<4,>=2",
|
|
||||||
"idna<4,>=2.5",
|
|
||||||
"urllib3<3,>=1.21.1",
|
|
||||||
]
|
|
||||||
files = [
|
|
||||||
{file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"},
|
|
||||||
{file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rich"
|
name = "rich"
|
||||||
version = "13.7.1"
|
version = "13.7.1"
|
||||||
@@ -1006,21 +925,6 @@ files = [
|
|||||||
{file = "wcmatch-8.5.1.tar.gz", hash = "sha256:c0088c7f6426cf6bf27e530e2b7b734031905f7e490475fd83c7c5008ab581b3"},
|
{file = "wcmatch-8.5.1.tar.gz", hash = "sha256:c0088c7f6426cf6bf27e530e2b7b734031905f7e490475fd83c7c5008ab581b3"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "webdriver-manager"
|
|
||||||
version = "4.0.1"
|
|
||||||
requires_python = ">=3.7"
|
|
||||||
summary = "Library provides the way to automatically manage drivers for different browsers"
|
|
||||||
dependencies = [
|
|
||||||
"packaging",
|
|
||||||
"python-dotenv",
|
|
||||||
"requests",
|
|
||||||
]
|
|
||||||
files = [
|
|
||||||
{file = "webdriver_manager-4.0.1-py2.py3-none-any.whl", hash = "sha256:d7970052295bb9cda2c1a24cf0b872dd2c41ababcc78f7b6b8dc37a41e979a7e"},
|
|
||||||
{file = "webdriver_manager-4.0.1.tar.gz", hash = "sha256:25ec177c6a2ce9c02fb8046f1b2732701a9418d6a977967bb065d840a3175d87"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wsproto"
|
name = "wsproto"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ dependencies = [
|
|||||||
"selenium~=4.18",
|
"selenium~=4.18",
|
||||||
"selenium_stealth~=1.0",
|
"selenium_stealth~=1.0",
|
||||||
"wcmatch~=8.5",
|
"wcmatch~=8.5",
|
||||||
"webdriver_manager~=4.0"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
|||||||
@@ -3,36 +3,24 @@ SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
|
|||||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
|
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
|
||||||
"""
|
"""
|
||||||
import logging, os, shutil, time
|
import logging, os, platform, shutil, time
|
||||||
from collections.abc import Callable, Iterable
|
from collections.abc import Callable, Iterable
|
||||||
from typing import Any, Final, TypeVar
|
from typing import Any, Final, TypeVar
|
||||||
|
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.common.exceptions import NoSuchElementException, TimeoutException, WebDriverException
|
from selenium.common.exceptions import NoSuchElementException, TimeoutException, WebDriverException
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.chrome.service import Service as ChromeService
|
|
||||||
from selenium.webdriver.chromium.options import ChromiumOptions
|
from selenium.webdriver.chromium.options import ChromiumOptions
|
||||||
from selenium.webdriver.chromium.webdriver import ChromiumDriver
|
from selenium.webdriver.chromium.webdriver import ChromiumDriver
|
||||||
from selenium.webdriver.edge.service import Service as EdgeService
|
|
||||||
from selenium.webdriver.remote.webdriver import WebDriver
|
from selenium.webdriver.remote.webdriver import WebDriver
|
||||||
from selenium.webdriver.remote.webelement import WebElement
|
from selenium.webdriver.remote.webelement import WebElement
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.webdriver.support.ui import Select, WebDriverWait
|
from selenium.webdriver.support.ui import Select, WebDriverWait
|
||||||
import selenium_stealth
|
import selenium_stealth
|
||||||
import webdriver_manager.core
|
|
||||||
from webdriver_manager.chrome import ChromeDriverManager
|
|
||||||
from webdriver_manager.core.driver_cache import DriverCacheManager
|
|
||||||
from webdriver_manager.core.manager import DriverManager
|
|
||||||
from webdriver_manager.core.os_manager import ChromeType, OSType, OperationSystemManager
|
|
||||||
from webdriver_manager.microsoft import EdgeChromiumDriverManager
|
|
||||||
|
|
||||||
from .utils import ensure, pause, T
|
from .utils import ensure, pause, T
|
||||||
|
|
||||||
LOG:Final[logging.Logger] = logging.getLogger("kleinanzeigen_bot.selenium_mixin")
|
LOG:Final[logging.Logger] = logging.getLogger("kleinanzeigen_bot.selenium_mixin")
|
||||||
|
|
||||||
DEFAULT_CHROMEDRIVER_PATH = "chromedriver"
|
|
||||||
DEFAULT_EDGEDRIVER_PATH = "msedgedriver"
|
|
||||||
|
|
||||||
|
|
||||||
class BrowserConfig:
|
class BrowserConfig:
|
||||||
|
|
||||||
@@ -102,51 +90,25 @@ class SeleniumMixin:
|
|||||||
LOG.info(" -> Chrome binary location: %s", self.browser_config.binary_location)
|
LOG.info(" -> Chrome binary location: %s", self.browser_config.binary_location)
|
||||||
return browser_options
|
return browser_options
|
||||||
|
|
||||||
def create_webdriver_session(self, *, use_preinstalled_webdriver:bool = True) -> None:
|
def create_webdriver_session(self) -> None:
|
||||||
LOG.info("Creating WebDriver session...")
|
LOG.info("Creating WebDriver session...")
|
||||||
|
|
||||||
if not LOG.isEnabledFor(logging.DEBUG):
|
|
||||||
os.environ['WDM_LOG_LEVEL'] = '0' # silence the web driver manager
|
|
||||||
|
|
||||||
# check if a chrome driver is present already
|
|
||||||
if use_preinstalled_webdriver and shutil.which(DEFAULT_CHROMEDRIVER_PATH):
|
|
||||||
LOG.info("Using pre-installed Chrome Driver [%s]", shutil.which(DEFAULT_CHROMEDRIVER_PATH))
|
|
||||||
self.webdriver = webdriver.Chrome(options = self._init_browser_options(webdriver.ChromeOptions()))
|
|
||||||
elif use_preinstalled_webdriver and shutil.which(DEFAULT_EDGEDRIVER_PATH):
|
|
||||||
LOG.info("Using pre-installed Edge Driver [%s]", shutil.which(DEFAULT_EDGEDRIVER_PATH))
|
|
||||||
self.webdriver = webdriver.ChromiumEdge(options = self._init_browser_options(webdriver.EdgeOptions()))
|
|
||||||
else:
|
|
||||||
# determine browser major version
|
|
||||||
if self.browser_config.binary_location:
|
if self.browser_config.binary_location:
|
||||||
ensure(os.path.exists(self.browser_config.binary_location), f"Specified browser binary [{self.browser_config.binary_location}] does not exist.")
|
ensure(os.path.exists(self.browser_config.binary_location), f"Specified browser binary [{self.browser_config.binary_location}] does not exist.")
|
||||||
chrome_type, chrome_version = self.get_browser_version(self.browser_config.binary_location)
|
|
||||||
else:
|
else:
|
||||||
browser_info = self.find_compatible_browser()
|
self.browser_config.binary_location = self.get_compatible_browser()
|
||||||
if browser_info is None:
|
|
||||||
raise AssertionError("No supported browser found!")
|
|
||||||
chrome_path, chrome_type, chrome_version = browser_info
|
|
||||||
self.browser_config.binary_location = chrome_path
|
|
||||||
LOG.info("Using Browser: %s %s [%s]", chrome_type.upper(), chrome_version, self.browser_config.binary_location)
|
|
||||||
chrome_major_version = chrome_version.split(".", 1)[0]
|
|
||||||
|
|
||||||
# hack to specify the concrete browser version for which the driver shall be downloaded
|
if "edge" in self.browser_config.binary_location.lower():
|
||||||
webdriver_manager.core.driver.get_browser_version_from_os = lambda _: chrome_major_version
|
os.environ["MSEDGEDRIVER_TELEMETRY_OPTOUT"] = "1" # https://docs.microsoft.com/en-us/microsoft-edge/privacy-whitepaper/#microsoft-edge-driver
|
||||||
|
browser_options = self._init_browser_options(webdriver.EdgeOptions())
|
||||||
# download and install matching chrome driver
|
browser_options.binary_location = self.browser_config.binary_location
|
||||||
webdriver_mgr: DriverManager
|
self.webdriver = webdriver.Edge(options = browser_options)
|
||||||
if chrome_type == ChromeType.MSEDGE:
|
|
||||||
webdriver_mgr = EdgeChromiumDriverManager(cache_manager = DriverCacheManager(valid_range = 14))
|
|
||||||
webdriver_path = webdriver_mgr.install()
|
|
||||||
env = os.environ.copy()
|
|
||||||
env["MSEDGEDRIVER_TELEMETRY_OPTOUT"] = "1" # https://docs.microsoft.com/en-us/microsoft-edge/privacy-whitepaper/#microsoft-edge-driver
|
|
||||||
self.webdriver = webdriver.ChromiumEdge(
|
|
||||||
service = EdgeService(webdriver_path, env = env),
|
|
||||||
options = self._init_browser_options(webdriver.EdgeOptions())
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
webdriver_mgr = ChromeDriverManager(chrome_type = chrome_type, cache_manager = DriverCacheManager(valid_range = 14))
|
browser_options = self._init_browser_options(webdriver.ChromeOptions())
|
||||||
webdriver_path = webdriver_mgr.install()
|
browser_options.binary_location = self.browser_config.binary_location
|
||||||
self.webdriver = webdriver.Chrome(service = ChromeService(webdriver_path), options = self._init_browser_options(webdriver.ChromeOptions()))
|
self.webdriver = webdriver.Chrome(options = browser_options)
|
||||||
|
|
||||||
|
LOG.info(" -> Chrome driver: %s", self.webdriver.service.path)
|
||||||
|
|
||||||
# workaround to support Edge, see https://github.com/diprajpatra/selenium-stealth/pull/25
|
# workaround to support Edge, see https://github.com/diprajpatra/selenium-stealth/pull/25
|
||||||
selenium_stealth.Driver = ChromiumDriver
|
selenium_stealth.Driver = ChromiumDriver
|
||||||
@@ -159,48 +121,9 @@ class SeleniumMixin:
|
|||||||
|
|
||||||
LOG.info("New WebDriver session is: %s %s", self.webdriver.session_id, self.webdriver.command_executor._url) # pylint: disable=protected-access
|
LOG.info("New WebDriver session is: %s %s", self.webdriver.session_id, self.webdriver.command_executor._url) # pylint: disable=protected-access
|
||||||
|
|
||||||
def get_browser_version(self, executable_path: str) -> tuple[ChromeType, str]: # -> [ chrome_type, chrome_version ]
|
def get_compatible_browser(self) -> str | None:
|
||||||
match OperationSystemManager.get_os_name():
|
match platform.system():
|
||||||
case OSType.WIN:
|
case "Linux":
|
||||||
import win32api # pylint: disable=import-outside-toplevel,import-error
|
|
||||||
# pylint: disable=no-member
|
|
||||||
lang, codepage = win32api.GetFileVersionInfo(executable_path, "\\VarFileInfo\\Translation")[0]
|
|
||||||
product_name = win32api.GetFileVersionInfo(executable_path, f"\\StringFileInfo\\{lang:04X}{codepage:04X}\\ProductName")
|
|
||||||
product_version = win32api.GetFileVersionInfo(executable_path, f"\\StringFileInfo\\{lang:04X}{codepage:04X}\\ProductVersion")
|
|
||||||
# pylint: enable=no-member
|
|
||||||
match product_name:
|
|
||||||
case "Chromium":
|
|
||||||
return (ChromeType.CHROMIUM, product_version)
|
|
||||||
case "Microsoft Edge":
|
|
||||||
return (ChromeType.MSEDGE, product_version)
|
|
||||||
case _: # "Google Chrome"
|
|
||||||
return (ChromeType.GOOGLE, product_version)
|
|
||||||
|
|
||||||
case OSType.LINUX:
|
|
||||||
version_cmd = webdriver_manager.core.utils.linux_browser_apps_to_cmd(f'"{executable_path}"')
|
|
||||||
|
|
||||||
case _:
|
|
||||||
version_cmd = f'"{executable_path}" --version'
|
|
||||||
|
|
||||||
filename = os.path.basename(executable_path).lower()
|
|
||||||
if "chromium" in filename:
|
|
||||||
return (
|
|
||||||
ChromeType.CHROMIUM,
|
|
||||||
webdriver_manager.core.utils.read_version_from_cmd(version_cmd, webdriver_manager.core.os_manager.PATTERN[ChromeType.CHROMIUM])
|
|
||||||
)
|
|
||||||
if "edge" in filename:
|
|
||||||
return (
|
|
||||||
ChromeType.MSEDGE,
|
|
||||||
webdriver_manager.core.utils.read_version_from_cmd(version_cmd, webdriver_manager.core.os_manager.PATTERN[ChromeType.MSEDGE])
|
|
||||||
)
|
|
||||||
return (
|
|
||||||
ChromeType.GOOGLE,
|
|
||||||
webdriver_manager.core.utils.read_version_from_cmd(version_cmd, webdriver_manager.core.os_manager.PATTERN[ChromeType.GOOGLE])
|
|
||||||
)
|
|
||||||
|
|
||||||
def find_compatible_browser(self) -> tuple[str, ChromeType, str] | None: # -> [ browser_path, chrome_type, chrome_version ]
|
|
||||||
match OperationSystemManager.get_os_name():
|
|
||||||
case OSType.LINUX:
|
|
||||||
browser_paths = [
|
browser_paths = [
|
||||||
shutil.which("chromium"),
|
shutil.which("chromium"),
|
||||||
shutil.which("chromium-browser"),
|
shutil.which("chromium-browser"),
|
||||||
@@ -208,14 +131,14 @@ class SeleniumMixin:
|
|||||||
shutil.which("microsoft-edge")
|
shutil.which("microsoft-edge")
|
||||||
]
|
]
|
||||||
|
|
||||||
case OSType.MAC:
|
case "Darwin":
|
||||||
browser_paths = [
|
browser_paths = [
|
||||||
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
||||||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
||||||
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
||||||
]
|
]
|
||||||
|
|
||||||
case OSType.WIN:
|
case "Windows":
|
||||||
browser_paths = [
|
browser_paths = [
|
||||||
os.environ.get("ProgramFiles", "C:\\Program Files") + r'\Microsoft\Edge\Application\msedge.exe',
|
os.environ.get("ProgramFiles", "C:\\Program Files") + r'\Microsoft\Edge\Application\msedge.exe',
|
||||||
os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)") + r'\Microsoft\Edge\Application\msedge.exe',
|
os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)") + r'\Microsoft\Edge\Application\msedge.exe',
|
||||||
@@ -239,10 +162,9 @@ class SeleniumMixin:
|
|||||||
|
|
||||||
for browser_path in browser_paths:
|
for browser_path in browser_paths:
|
||||||
if browser_path and os.path.isfile(browser_path):
|
if browser_path and os.path.isfile(browser_path):
|
||||||
return (browser_path, *self.get_browser_version(browser_path))
|
return browser_path
|
||||||
|
|
||||||
LOG.warning("Installed browser could not be detected")
|
raise AssertionError("Installed browser could not be detected")
|
||||||
return None
|
|
||||||
|
|
||||||
def web_await(self, condition: Callable[[WebDriver], T], timeout:float = 5, exception_on_timeout: Callable[[], Exception] | None = None) -> T:
|
def web_await(self, condition: Callable[[WebDriver], T], timeout:float = 5, exception_on_timeout: Callable[[], Exception] | None = None) -> T:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -14,19 +14,9 @@ def test_webdriver_auto_init():
|
|||||||
selenium_mixin = SeleniumMixin()
|
selenium_mixin = SeleniumMixin()
|
||||||
selenium_mixin.browser_config.arguments = ["--no-sandbox"]
|
selenium_mixin.browser_config.arguments = ["--no-sandbox"]
|
||||||
|
|
||||||
browser_info = selenium_mixin.find_compatible_browser()
|
browser_path = selenium_mixin.get_compatible_browser()
|
||||||
utils.ensure(browser_info is not None, "Chrome type not auto-detected")
|
utils.ensure(browser_path is not None, "Browser not auto-detected")
|
||||||
|
|
||||||
chrome_path, chrome_type, chrome_version = browser_info
|
|
||||||
utils.ensure(chrome_path is not None, "Chrome type not auto-detected")
|
|
||||||
utils.ensure(chrome_type is not None, "Chrome type not auto-detected")
|
|
||||||
utils.ensure(chrome_version is not None, "Chrome version not auto-detected")
|
|
||||||
|
|
||||||
utils.ensure(selenium_mixin.webdriver is None, "Web driver must not be set before create_webdriver_session()")
|
|
||||||
selenium_mixin.create_webdriver_session(use_preinstalled_webdriver = True)
|
|
||||||
utils.ensure(selenium_mixin.webdriver is not None, "Web driver must be set after create_webdriver_session()")
|
|
||||||
selenium_mixin.webdriver.quit()
|
|
||||||
|
|
||||||
selenium_mixin.webdriver = None
|
selenium_mixin.webdriver = None
|
||||||
selenium_mixin.create_webdriver_session(use_preinstalled_webdriver = False)
|
selenium_mixin.create_webdriver_session()
|
||||||
selenium_mixin.webdriver.quit()
|
selenium_mixin.webdriver.quit()
|
||||||
|
|||||||
Reference in New Issue
Block a user