Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_element_visible: Check for StaleElementReferenceException #903

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions splinter/driver/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,38 @@ 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:
return True
try:
if finder(selector, wait_time=wait_time) and finder(selector, wait_time=wait_time).visible:
return True
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 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