Skip to content

Commit c6d43c4

Browse files
committed
FIX: Correction when instantiating the driver with undetected
1 parent ea8e366 commit c6d43c4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

botcity/web/bot.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from botcity.base.utils import only_if_element
1818
from bs4 import BeautifulSoup
1919
from PIL import Image
20-
from selenium.common.exceptions import InvalidSessionIdException
20+
from selenium.common.exceptions import InvalidSessionIdException, WebDriverException
2121
from selenium.webdriver.common.action_chains import ActionChains
2222
from selenium.common.exceptions import StaleElementReferenceException
2323
from selenium.webdriver.common.by import By
@@ -260,10 +260,26 @@ def check_driver():
260260
self.capabilities = cap
261261
driver_path = self.driver_path or check_driver()
262262
self.driver_path = driver_path
263-
self._driver = driver_class(**self._get_parameters_to_driver())
263+
self._driver = self._instance_driver(driver_class=driver_class)
264264
self._others_configurations()
265265
self.set_screen_resolution()
266266

267+
def _instance_driver(self, driver_class):
268+
parameters = self._get_parameters_to_driver()
269+
try:
270+
driver = driver_class(**parameters)
271+
except WebDriverException as error:
272+
if 'This version of ChromeDriver only supports Chrome version' in error.msg:
273+
try:
274+
correct_version = int(error.msg.split('Current browser version is ')[1].split('.')[0])
275+
except Exception:
276+
raise error
277+
parameters["version_main"] = correct_version
278+
driver = driver_class(**parameters)
279+
else:
280+
raise error
281+
return driver
282+
267283
def _get_parameters_to_driver(self):
268284
if self.browser == Browser.UNDETECTED_CHROME:
269285
return {"options": self.options,

0 commit comments

Comments
 (0)