Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

regression in python bindings 2.40: element.click() fails in some circumstances #7073

Open
lukeis opened this issue Mar 4, 2016 · 7 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 4, 2016

Originally reported on Google Code with ID 7073

I've started seeing weird behaviour in tests since i upgraded to v 2.40 of the Python
bindings.  It doesn't happen in 2.39.

(Ubuntu 13.10, Firefox)

here's the basic code:

self.browser.find_element_by_link_text('Reticulate splines').click()
self.assertEqual(self.browser.current_url, first_list_url)

Essentially, this expects the URL to change after we click a link.  It's a normal link,
no javascript magic.

Now, I understand there may be a race condition here, there's no guarantee that the
page load that's triggered by the click will have completed by the time I ask for the
browser.current_url.  I found it tended to always work locally, but would sometimes
fail under jenkins CI.

So I built a little wait loop:

        self.browser.find_element_by_link_text('Reticulate splines').click()
        self.wait_for(
            lambda: self.assertEqual(self.browser.current_url, first_list_url)
        )


[...]

    def wait_for(self, function_with_assertion, timeout=DEFAULT_WAIT):
        start_time = time.time()
        while time.time() - start_time < timeout:
            try:
                time.sleep(0.2)  # sleep first to let things settle
                return function_with_assertion()
            except (AssertionError, WebDriverException):
                pass
        # one more try, which will raise any errors if they are outstanding
        return function_with_assertion()

And that works, both locally and on jenkins.  But once I upgraded to selenium 2.40,
it started failing again.  It looks like the click just wasn't going through.

Some things I've tried:

- switching to PhantomJS.  that produced an intriguing error, on the click that precedes
the browser url check, saying "click succeeded but load failed"... that seemed relevant
perhaps?

- i worried that the call to browser.currrent_url was happening too soon after the
click, so it was somehow interrupting it. i put a time.sleep after.  no dice.

- i tried adding a little retry loop, where it tries to click a second time. that works.
 but it kinda sucks.

- i tried taking screenshots.  a basic selenium screenshot show the page with the link
hover active, but stuck on the page with the link.  a full os screenshot shows the
little link-hover-url-thingy.  that click is definitely hanging somehow.

- i'm using the latest selenium (2.40)
- i'm using the latest firefox (27.0.1)
- i'm using xvfb both locally and on the server, so that's not it
- i thought it might be server-side:  the server is spawned in a thread by django liveservertestcase.
 i set the test to run against a separate staging server instead.  the error still
occurs.

I've had a bit of a try at producing a minimal repro, but no dice.  it only seems to
affect one test out of 6 in my test suite.  my repo *is* publicly available though,
so feel free to use it to try and repro:

https://github.com/hjwp/book-example/tree/chapter_19

to run the failing test:

python3 manage.py test functional_tests.test_my_lists






Reported by harry.percival on 2014-03-09 10:37:29


- _Attachment: MyListsTest.test_logged_in_users_lists_are_saved_as_my_lists-window0-2014-03-08T19.12.44.png
![MyListsTest.test_logged_in_users_lists_are_saved_as_my_lists-window0-2014-03-08T19.12.44.png](https://storage.googleapis.com/google-code-attachments/selenium/issue-7073/comment-0/MyListsTest.test_logged_in_users_lists_are_saved_as_my_lists-window0-2014-03-08T19.12.44.png)_ - _Attachment: MyListsTest.test_logged_in_users_lists_are_saved_as_my_lists-window0-2014-03-08T19.17.17.fullscreen.png
![MyListsTest.test_logged_in_users_lists_are_saved_as_my_lists-window0-2014-03-08T19.17.17.fullscreen.png](https://storage.googleapis.com/google-code-attachments/selenium/issue-7073/comment-0/MyListsTest.test_logged_in_users_lists_are_saved_as_my_lists-window0-2014-03-08T19.17.17.fullscreen.png)_
@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Reported by barancev on 2014-03-12 09:29:16

  • Labels added: Browser-Firefox

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I can confirm this regression is still present in 2.41.

to repro, you can just check out

https://github.com/hjwp/book-example/tree/chapter_18

and run:

python3 manage.py test

it'll take about 3 minutes and show you several failures.  downgrade back to 2.39 and
everything passes.





Reported by harry.percival on 2014-04-02 11:10:58

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Let me know if there's anything I can do to help debug.  My book's about to go to print,
i'd be sad to have to put it out there saying "don't use the latest selenium, it's
broken."


Reported by harry.percival on 2014-04-02 11:18:10

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Aha!   I have reports (https://twitter.com/k_sze/status/451366131668762624) that it
works OK on MacOS.  I was testing on Ubuntu.  Will spin up a windows vm quickly....

Reported by harry.percival on 2014-04-02 14:33:05

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Aha.  narrowing it down.  Looks like it doesn't happens on Windows, and it doesn't happen
on linux *unless* I use xvfb.

So this doesn't affect regular use on the desktop, but it does affect anyone using
xvfb, ie presumably anyone running selenium tests in headless CI / jenkins, etc...

Reported by harry.percival on 2014-04-02 14:52:23

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Just been running a few more tests to confirm things:

2.39 is ok for both
2.40 broken for xvfb, ok for normal display use
2.41 broken for xvfb, ok for normal display use

2.40 also works ok on windows.  so it seems like just linux/xvfb has the regression.

i'm on ubuntu 13.10 with firefox 27.0.1 still

Reported by harry.percival on 2014-04-02 15:11:47

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Reported by luke.semerau on 2015-09-17 17:46:33

  • Labels added: Restrict-AddIssueComment-Commit

@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant