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

Conversation

tony
Copy link
Contributor

@tony tony commented Jul 29, 2021

Robust, consistent handling for is_element_visible_by_? and is_element_not_visible_by_?. We don't want either to blink at stale references.

Prior art: consistent with #396, the function can continue to poll "freshly" without interruption by stale objects

Fixes #934

@tony tony force-pushed the tn-uniform-stale-catching branch from 9a776f4 to e399957 Compare July 30, 2021 19:40
@tony tony changed the title is_element_(not_)_visible: Check for StaleElementReferenceException is_element_(not_)_visible: Check for StaleElementReferenceException Jul 30, 2021
@tony tony changed the title is_element_(not_)_visible: Check for StaleElementReferenceException is_element_visible: Check for StaleElementReferenceException Jul 30, 2021
@tony tony changed the title is_element_visible: Check for StaleElementReferenceException is_element_visible: Check for StaleElementReferenceException Jul 30, 2021
@tony
Copy link
Contributor Author

tony commented Jul 30, 2021

@jsfehler this can be reran now. This should fix the test

@tony
Copy link
Contributor Author

tony commented Aug 18, 2021

@jsfehler

Anything more you'd like to see for this?

rationale:

  • consistency
  • fixes issues of StaleElementReferenceException burping unexpectedly
  • is_element_visible is is_element_not_visible isn't checking whether something is stale - it's checking whether the element does / doesn't exist

my personal rationale is the same as when #396 did it's stale checks. just making sure the ones have it too

@tony tony force-pushed the tn-uniform-stale-catching branch from e399957 to dbaa101 Compare October 2, 2021 22:43
@tony
Copy link
Contributor Author

tony commented Oct 2, 2021

Another friendly hello! :)

And a rebase! 🙌

@tony tony force-pushed the tn-uniform-stale-catching branch from dbaa101 to b8b87d7 Compare October 21, 2021 19:13
@tony
Copy link
Contributor Author

tony commented Oct 21, 2021

Rebased again!

@tony
Copy link
Contributor Author

tony commented Oct 21, 2021

This avoids the stale exception when checking for an element's visibility. Right now, we correctly do this in is_text_present via #396, in my change it's added to is_element_visible too.

Anyone around? Can someone please take a look?

@jsfehler
Copy link
Collaborator

@tony There's a few problems with this PR:
1 - You're missing unit tests for this PR. There aren't any tests to make sure is_element_visible / is_element_not_visible doesn't choke on those exceptions.
2 - There's no point letting ValueError escape here. ValueError shouldn't be raised by find_by. Unless you have a specific scenario in mind that I haven't thought of.

@tony tony force-pushed the tn-uniform-stale-catching branch from b8b87d7 to bb1fb2f Compare October 25, 2021 23:23
@tony
Copy link
Contributor Author

tony commented Oct 25, 2021

@jsfehler thank you for the response!

  1. In Check for StaleElementReferenceException #396, a similar PR that got merged, I don't see any tests. How would you suggest to write a test that raises StaleElementReferenceException?
  2. Fixed!

@jsfehler
Copy link
Collaborator

@tony Having re-read this PR, I'm not sure these changes will actually have any effect.

find_by already catches NoSuchElementException and StaleElementReferenceException. I can't think of a scenario in which these checks are not redundant.

Do you have a particular scenario where is_element_visible or is_element_not_visible are currently failing?

@tony
Copy link
Contributor Author

tony commented Oct 26, 2021

@jsfehler Here's the traceback: #934 (as of 0.14.0)

I agree with you, maybe I'm misunderstanding something?

I reviewed the code and StaleElementReferenceException is ultimately caught.

I haven't gotten this since, should I close this?

@jsfehler
Copy link
Collaborator

@tony It looks like the call to Webdriver's is_displayed() method is what's causing your failure. The best way to handle this is isolating the part that can be flaky:

while time.time() < end_time:
    is_visible = False
    element = finder(selector, wait_time=wait_time)
    if element:
        try:
            is_visible = element.visible
        except StaleElementReferenceException:
            pass
    if is_visible:
        return True

return False

@jsfehler
Copy link
Collaborator

jsfehler commented Jul 6, 2022

Closing this due to #1064

The new behaviour should be sufficient in this case.

@jsfehler jsfehler closed this Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

is_element_visible raises StaleElementReferenceException
2 participants