Skip to content

Commit 4f47c4c

Browse files
committed
Add method for bringing a page object to the front with Z-index.
1 parent f288bfd commit 4f47c4c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,24 @@ def activate_jquery(self):
658658
# Since jQuery still isn't activating, give up and raise an exception
659659
raise Exception("Exception: WebDriver could not activate jQuery!")
660660

661+
def bring_to_front(self, selector, by=By.CSS_SELECTOR):
662+
""" Updates the Z-index of a page element to bring it into view.
663+
Useful when getting a WebDriverException, such as the one below:
664+
{ Element is not clickable at point (#, #).
665+
Other element would receive the click: ... } """
666+
if page_utils.is_xpath_selector(selector):
667+
by = By.XPATH
668+
self.find_element(selector, by=by, timeout=settings.SMALL_TIMEOUT)
669+
try:
670+
selector = self.convert_to_css_selector(selector, by=by)
671+
except Exception:
672+
# Don't perform action if can't convert to CSS_SELECTOR for jQuery
673+
return
674+
675+
script = ("""document.querySelector('%s').style.zIndex = "1";"""
676+
% selector)
677+
self.execute_script(script)
678+
661679
def highlight(self, selector, by=By.CSS_SELECTOR,
662680
loops=settings.HIGHLIGHTS, scroll=True):
663681
""" This method uses fancy javascript to highlight an element.

0 commit comments

Comments
 (0)