Skip to content

Commit 2efd21c

Browse files
committed
Add a customizable "timeout" arg to "highlight()" methods
1 parent 0695e51 commit 2efd21c

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

help_docs/method_summary.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,14 @@ self.bring_active_window_to_front()
363363

364364
self.bring_to_front(selector, by="css selector")
365365

366-
self.highlight_click(selector, by="css selector", loops=3, scroll=True)
366+
self.highlight_click(selector, by="css selector", loops=3, scroll=True, timeout=None)
367367

368-
self.highlight_type(selector, text, by="css selector", loops=3, scroll=True)
368+
self.highlight_type(selector, text, by="css selector", loops=3, scroll=True, timeout=None)
369369
# Duplicates:
370-
# self.highlight_update_text(selector, text, by="css selector", loops=3, scroll=True)
370+
# self.highlight_update_text(
371+
# selector, text, by="css selector", loops=3, scroll=True, timeout=None)
371372

372-
self.highlight(selector, by="css selector", loops=4, scroll=True)
373+
self.highlight(selector, by="css selector", loops=4, scroll=True, timeout=None)
373374

374375
self.press_up_arrow(selector="html", times=1, by="css selector")
375376

seleniumbase/fixtures/base_case.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5508,29 +5508,50 @@ def bring_to_front(self, selector, by="css selector"):
55085508
self.execute_script(script)
55095509

55105510
def highlight_click(
5511-
self, selector, by="css selector", loops=3, scroll=True
5511+
self, selector, by="css selector", loops=3, scroll=True, timeout=None,
55125512
):
55135513
"""Highlights the element and then clicks it."""
55145514
self.__check_scope()
5515+
if not timeout:
5516+
timeout = settings.SMALL_TIMEOUT
5517+
self.wait_for_element_visible(selector, by=by, timeout=timeout)
55155518
if not self.demo_mode:
55165519
self.__highlight(selector, by=by, loops=loops, scroll=scroll)
55175520
self.click(selector, by=by)
55185521

55195522
def highlight_update_text(
5520-
self, selector, text, by="css selector", loops=3, scroll=True
5523+
self,
5524+
selector,
5525+
text,
5526+
by="css selector",
5527+
loops=3,
5528+
scroll=True,
5529+
timeout=None,
55215530
):
55225531
"""Highlights the element and then types text into the field."""
55235532
self.__check_scope()
5533+
if not timeout:
5534+
timeout = settings.SMALL_TIMEOUT
5535+
self.wait_for_element_visible(selector, by=by, timeout=timeout)
55245536
if not self.demo_mode:
55255537
self.__highlight(selector, by=by, loops=loops, scroll=scroll)
55265538
self.update_text(selector, text, by=by)
55275539

55285540
def highlight_type(
5529-
self, selector, text, by="css selector", loops=3, scroll=True
5541+
self,
5542+
selector,
5543+
text,
5544+
by="css selector",
5545+
loops=3,
5546+
scroll=True,
5547+
timeout=None,
55305548
):
55315549
"""Same as self.highlight_update_text()
55325550
As above, highlights the element and then types text into the field."""
55335551
self.__check_scope()
5552+
if not timeout:
5553+
timeout = settings.SMALL_TIMEOUT
5554+
self.wait_for_element_visible(selector, by=by, timeout=timeout)
55345555
if not self.demo_mode:
55355556
self.__highlight(selector, by=by, loops=loops, scroll=scroll)
55365557
self.update_text(selector, text, by=by)
@@ -5613,15 +5634,26 @@ def __highlight(
56135634
pass # JQuery probably couldn't load. Skip highlighting.
56145635
time.sleep(0.065)
56155636

5616-
def highlight(self, selector, by="css selector", loops=None, scroll=True):
5637+
def highlight(
5638+
self,
5639+
selector,
5640+
by="css selector",
5641+
loops=None,
5642+
scroll=True,
5643+
timeout=None,
5644+
):
56175645
"""This method uses fancy JavaScript to highlight an element.
56185646
@Params
56195647
selector - the selector of the element to find
56205648
by - the type of selector to search by (Default: CSS)
56215649
loops - # of times to repeat the highlight animation
56225650
(Default: 4. Each loop lasts for about 0.2s)
5623-
scroll - the option to scroll to the element first (Default: True) """
5651+
scroll - the option to scroll to the element first (Default: True)
5652+
timeout - the time to wait for the element to appear """
56245653
self.__check_scope()
5654+
if not timeout:
5655+
timeout = settings.SMALL_TIMEOUT
5656+
self.wait_for_element_visible(selector, by=by, timeout=timeout)
56255657
self.__highlight(selector=selector, by=by, loops=loops, scroll=scroll)
56265658
if self.recorder_mode and self.__current_url_is_recordable():
56275659
if self.get_session_storage_item("pause_recorder") == "no":

0 commit comments

Comments
 (0)