Skip to content

Commit 3d3359e

Browse files
committed
Maintain compatibility with Selenium 2 if still being used
1 parent 6f7d76b commit 3d3359e

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ class MyTestClass(BaseCase):
4545
from seleniumbase.fixtures import page_utils
4646
from seleniumbase.fixtures import xpath_to_css
4747
from selenium.common.exceptions import (StaleElementReferenceException,
48-
ElementNotInteractableException,
4948
TimeoutException,
5049
WebDriverException)
50+
from selenium.common import exceptions as selenium_exceptions
51+
try:
52+
# Selenium 3
53+
ENI_Exception = selenium_exceptions.ElementNotInteractableException
54+
except Exception:
55+
# Selenium 2 (Keep compatibility with seleneium 2.53.6 if still being used)
56+
ENI_Exception = selenium_exceptions.ElementNotSelectableException
5157
from selenium.webdriver.remote.webdriver import WebDriver
5258
from selenium.webdriver.common.by import By
5359
from selenium.webdriver.common.keys import Keys
@@ -97,8 +103,7 @@ def click(self, selector, by=By.CSS_SELECTOR,
97103
pre_action_url = self.driver.current_url
98104
try:
99105
element.click()
100-
except (StaleElementReferenceException,
101-
ElementNotInteractableException):
106+
except (StaleElementReferenceException, ENI_Exception):
102107
self.wait_for_ready_state_complete()
103108
time.sleep(0.05)
104109
element = page_actions.wait_for_element_visible(
@@ -129,8 +134,7 @@ def double_click(self, selector, by=By.CSS_SELECTOR,
129134
actions.move_to_element(element)
130135
actions.double_click(element)
131136
actions.perform()
132-
except (StaleElementReferenceException,
133-
ElementNotInteractableException):
137+
except (StaleElementReferenceException, ENI_Exception):
134138
self.wait_for_ready_state_complete()
135139
time.sleep(0.05)
136140
element = page_actions.wait_for_element_visible(
@@ -194,8 +198,7 @@ def click_link_text(self, link_text, timeout=settings.SMALL_TIMEOUT):
194198
pre_action_url = self.driver.current_url
195199
try:
196200
element.click()
197-
except (StaleElementReferenceException,
198-
ElementNotInteractableException):
201+
except (StaleElementReferenceException, ENI_Exception):
199202
self.wait_for_ready_state_complete()
200203
time.sleep(0.05)
201204
element = self.wait_for_link_text_visible(
@@ -251,8 +254,7 @@ def click_partial_link_text(self, partial_link_text,
251254
pre_action_url = self.driver.current_url
252255
try:
253256
element.click()
254-
except (StaleElementReferenceException,
255-
ElementNotInteractableException):
257+
except (StaleElementReferenceException, ENI_Exception):
256258
self.wait_for_ready_state_complete()
257259
time.sleep(0.05)
258260
element = self.wait_for_partial_link_text(
@@ -278,8 +280,7 @@ def get_text(self, selector, by=By.CSS_SELECTOR,
278280
self.driver, selector, by, timeout)
279281
try:
280282
element_text = element.text
281-
except (StaleElementReferenceException,
282-
ElementNotInteractableException):
283+
except (StaleElementReferenceException, ENI_Exception):
283284
self.wait_for_ready_state_complete()
284285
time.sleep(0.06)
285286
element = page_actions.wait_for_element_visible(
@@ -299,8 +300,7 @@ def get_attribute(self, selector, attribute, by=By.CSS_SELECTOR,
299300
self.driver, selector, by, timeout)
300301
try:
301302
attribute_value = element.get_attribute(attribute)
302-
except (StaleElementReferenceException,
303-
ElementNotInteractableException):
303+
except (StaleElementReferenceException, ENI_Exception):
304304
self.wait_for_ready_state_complete()
305305
time.sleep(0.06)
306306
element = page_actions.wait_for_element_present(
@@ -361,8 +361,7 @@ def add_text(self, selector, new_value, by=By.CSS_SELECTOR,
361361
element.send_keys(Keys.RETURN)
362362
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
363363
self.wait_for_ready_state_complete()
364-
except (StaleElementReferenceException,
365-
ElementNotInteractableException):
364+
except (StaleElementReferenceException, ENI_Exception):
366365
self.wait_for_ready_state_complete()
367366
time.sleep(0.06)
368367
element = self.wait_for_element_visible(
@@ -411,8 +410,7 @@ def update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
411410
self._scroll_to_element(element)
412411
try:
413412
element.clear()
414-
except (StaleElementReferenceException,
415-
ElementNotInteractableException):
413+
except (StaleElementReferenceException, ENI_Exception):
416414
self.wait_for_ready_state_complete()
417415
time.sleep(0.06)
418416
element = self.wait_for_element_visible(
@@ -429,8 +427,7 @@ def update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
429427
element.send_keys(Keys.RETURN)
430428
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
431429
self.wait_for_ready_state_complete()
432-
except (StaleElementReferenceException,
433-
ElementNotInteractableException):
430+
except (StaleElementReferenceException, ENI_Exception):
434431
self.wait_for_ready_state_complete()
435432
time.sleep(0.06)
436433
element = self.wait_for_element_visible(
@@ -631,8 +628,7 @@ def scroll_to(self, selector, by=By.CSS_SELECTOR,
631628
selector, by=by, timeout=timeout)
632629
try:
633630
self._scroll_to_element(element)
634-
except (StaleElementReferenceException,
635-
ElementNotInteractableException):
631+
except (StaleElementReferenceException, ENI_Exception):
636632
self.wait_for_ready_state_complete()
637633
time.sleep(0.05)
638634
element = self.wait_for_element_visible(
@@ -1274,8 +1270,7 @@ def _pick_select_option(self, dropdown_selector, option,
12741270
Select(element).select_by_value(option)
12751271
else:
12761272
Select(element).select_by_visible_text(option)
1277-
except (StaleElementReferenceException,
1278-
ElementNotInteractableException):
1273+
except (StaleElementReferenceException, ENI_Exception):
12791274
self.wait_for_ready_state_complete()
12801275
time.sleep(0.05)
12811276
element = self.find_element(

0 commit comments

Comments
 (0)