Skip to content

Commit d23187b

Browse files
committed
Improve reliability of methods that make JavaScript calls
1 parent 81482e4 commit d23187b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5338,6 +5338,11 @@ def jquery_click_all(self, selector, by="css selector"):
53385338
def hide_element(self, selector, by="css selector"):
53395339
"""Hide the first element on the page that matches the selector."""
53405340
self.__check_scope()
5341+
try:
5342+
self.wait_for_element_visible("body", timeout=1.5)
5343+
self.wait_for_element_present(selector, by=by, timeout=0.5)
5344+
except Exception:
5345+
pass
53415346
selector, by = self.__recalculate_selector(selector, by)
53425347
css_selector = self.convert_to_css_selector(selector, by=by)
53435348
if ":contains(" in css_selector:
@@ -5356,6 +5361,10 @@ def hide_element(self, selector, by="css selector"):
53565361
def hide_elements(self, selector, by="css selector"):
53575362
"""Hide all elements on the page that match the selector."""
53585363
self.__check_scope()
5364+
try:
5365+
self.wait_for_element_visible("body", timeout=1.5)
5366+
except Exception:
5367+
pass
53595368
selector, by = self.__recalculate_selector(selector, by)
53605369
css_selector = self.convert_to_css_selector(selector, by=by)
53615370
if ":contains(" in css_selector:
@@ -5377,6 +5386,11 @@ def hide_elements(self, selector, by="css selector"):
53775386
def show_element(self, selector, by="css selector"):
53785387
"""Show the first element on the page that matches the selector."""
53795388
self.__check_scope()
5389+
try:
5390+
self.wait_for_element_visible("body", timeout=1.5)
5391+
self.wait_for_element_present(selector, by=by, timeout=1)
5392+
except Exception:
5393+
pass
53805394
selector, by = self.__recalculate_selector(selector, by)
53815395
css_selector = self.convert_to_css_selector(selector, by=by)
53825396
if ":contains(" in css_selector:
@@ -5396,6 +5410,10 @@ def show_element(self, selector, by="css selector"):
53965410
def show_elements(self, selector, by="css selector"):
53975411
"""Show all elements on the page that match the selector."""
53985412
self.__check_scope()
5413+
try:
5414+
self.wait_for_element_visible("body", timeout=1.5)
5415+
except Exception:
5416+
pass
53995417
selector, by = self.__recalculate_selector(selector, by)
54005418
css_selector = self.convert_to_css_selector(selector, by=by)
54015419
if ":contains(" in css_selector:
@@ -5417,6 +5435,11 @@ def show_elements(self, selector, by="css selector"):
54175435
def remove_element(self, selector, by="css selector"):
54185436
"""Remove the first element on the page that matches the selector."""
54195437
self.__check_scope()
5438+
try:
5439+
self.wait_for_element_visible("body", timeout=1.5)
5440+
self.wait_for_element_present(selector, by=by, timeout=0.5)
5441+
except Exception:
5442+
pass
54205443
selector, by = self.__recalculate_selector(selector, by)
54215444
css_selector = self.convert_to_css_selector(selector, by=by)
54225445
if ":contains(" in css_selector:
@@ -5436,6 +5459,10 @@ def remove_element(self, selector, by="css selector"):
54365459
def remove_elements(self, selector, by="css selector"):
54375460
"""Remove all elements on the page that match the selector."""
54385461
self.__check_scope()
5462+
try:
5463+
self.wait_for_element_visible("body", timeout=1.5)
5464+
except Exception:
5465+
pass
54395466
selector, by = self.__recalculate_selector(selector, by)
54405467
css_selector = self.convert_to_css_selector(selector, by=by)
54415468
if ":contains(" in css_selector:

0 commit comments

Comments
 (0)