Skip to content

Commit

Permalink
is_element_(not_)_visible: Check for StaleElementReferenceException
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Jul 29, 2021
1 parent 75c790b commit 9a776f4
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions splinter/driver/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,43 @@ def is_element_visible(self, finder, selector, wait_time=None):
end_time = time.time() + wait_time

while time.time() < end_time:
if finder(selector, wait_time=wait_time) and finder(selector, wait_time=wait_time).visible:
try:
if finder(selector, wait_time=wait_time) and finder(selector, wait_time=wait_time).visible:
return True
return True
except ValueError:
pass
except NoSuchElementException:
# This exception will be thrown if the body tag isn't present
# This has occasionally been observed. Assume that the
# page isn't fully loaded yet
pass
except StaleElementReferenceException:
# This exception is sometimes thrown if the page changes
# quickly
pass
return False

def is_element_not_visible(self, finder, selector, wait_time=None):
wait_time = wait_time or self.wait_time
end_time = time.time() + wait_time

while time.time() < end_time:
element = finder(selector, wait_time=0)
if not element or (element and not element.visible):
return True
try:
element = finder(selector, wait_time=0)
if not element or (element and not element.visible):
return True
except ValueError:
pass
except NoSuchElementException:
# This exception will be thrown if the body tag isn't present
# This has occasionally been observed. Assume that the
# page isn't fully loaded yet
pass
except StaleElementReferenceException:
# This exception is sometimes thrown if the page changes
# quickly
pass
return False

def is_element_visible_by_css(self, css_selector, wait_time=None):
Expand Down

0 comments on commit 9a776f4

Please sign in to comment.