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

phantomjs different behaviour to firefox/chrome, eg for implicty_wait and current_url #6497

Closed
lukeis opened this issue Mar 4, 2016 · 11 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 4, 2016

Originally reported on Google Code with ID 6497

I tried to switch over a set of selenium tests from using Firefox to PhantomJS, and
found several things didn't work in the same way at all.  Possibly these are just race
conditions.

Here's a couple of minimal repros:

* current_url not updated after submitting input on form:
https://gist.github.com/hjwp/7216676


* selenium loads content from old page after form submission
https://gist.github.com/hjwp/7216765

I've also seen StaleElementException errors in similar situations.

Questions:
- Am I correct to assume that "send_keys" should notice if it is doing a form submission,
and wait for the page to load if so?  Or is that just wishful thinking?
- ie: are these different behaviours in Firefox and Phantomjs expected?  Is this a
race condition, was I just lucky my firefox code ever worked?  If so i need to be using
the wait api a lot more...

Reported by harry.percival on 2013-10-29 15:29:22

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Reported by barancev on 2013-10-29 16:59:52

  • Labels added: Browser-PhantomJS

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Implicit waits are applied to find_element and find_elements operations only. They allow
to wait for an element to appear on the page. No operations (other than open) being
performed waits for the "next" page to be loaded. To avoid race conditions use proper
waiting strategy. Read [1] for examples.

[1] https://blog.mozilla.org/webqa/2012/07/12/how-to-webdriverwait/

Reported by barancev on 2013-10-30 11:26:12

  • Status changed: WorkingAsIntended

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Thanks for the clarification.  So, out of curiosity then, you say `find_elements` is
affected by implicitly_wait, does that mean that if `find_elements` finds 0 elements,
it retries until the wait timeout expires before returning an empty list?

`find_elements` might be a good compromise for me then. It would make things slower
when no elements are expected, but OTOH it might work as  a nice lightweight way for
me to get the implicit waits I want...

Reported by harry.percival on 2013-10-30 11:31:02

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

>> if `find_elements` finds 0 elements, it retries until the wait timeout expires before
returning an empty list?

Exactly so.

Reported by barancev on 2013-10-30 11:42:16

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Aplogies for thinking out loud in what is probably the wrong place, but come to think
of it, find_elements won't work.  If, for example, I have a POST request that will
add an element to a table on the page, then I can't use find_elements to wait for the
second row to appear.


What this means is that, even for the absolute simplest of tests, I need to use some
kind of waitfor.  That's annoying*.  Surely webdriver can tell the difference between
a javascript-initiated GET or POST and a hyperlink/form-initiated one?  I mean, the
blog post says that's hard, but really?


* although not as annoying as having users moan and issue ill-informed feature requests
in bug reports.  Feel free to tell me to shut up.


Reported by harry.percival on 2013-10-30 11:43:34

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Nobody can predict that "after a user clicks this button a new row should be added to
that table". But if you know this is expected result you have to wait for the expected
table size, ot for the size to be changed, or for the size to stop changing, or for
the activity indicator to disappear, or for something else. Remember there is no universal
solution to the halting problem [1]

[1] http://en.wikipedia.org/wiki/Halting_problem

Reported by barancev on 2013-10-30 11:59:09

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Ah, the old halting problem, the bane of all our lives.  Pending a workaround for that,
here's my dream solution, which feels like it would solve my problems and feel intuitive
(surely if *I* find it intuitive, then everybody else on earth will too, right?)

1) webdriver can tell the difference between javascript-initiated stuff and non-javascript
browser interactions
2) so if we click a hyperlink which causes a browser GET, or we click a form submit
button that causes a browser POST,
3) webdriver will now invalidate its caches and wait for the DOM to load, so that my
next calls to, eg, find_elements, will pick up stuff from the new page.

But maybe my assumption at 1) is not correct?  Or maybe part 3) is way more complex
than I think? Or maybe the feeling is that, yes, it is all theoretically possible,
but it's too much effort to bother doing a bunch of work for a solution that works
well for non-javascript websites, given that the whole world is building javascript-heavy
sites these days?

Reported by harry.percival on 2013-10-30 12:27:40

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Selenium does not wait for all AJAX interation to complete. Because it is asynchronous
in nature. A real user does not wait, she clicks another button as soon as it is available.
Despite th fact that "some AJAX requests are not processed yet, and the DOM is still
rebuilding". It is not a user problem. And Selenium simulates such a user :)

Reported by barancev on 2013-10-30 14:35:56

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Thanks for persisting with the conversation, I appreciate it.

I was talking about non-AJAX requests, sorry that wasn't clear.  Can Selenium tell
the difference?  And, if so, could it do some more "intuitive" things in the case of
non-Ajax/normal requests?  ie, wait until the new page has properly loaded?

Reported by harry.percival on 2013-10-30 15:08:55

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

You welcome to the selenium dev list [1] with questions about design decisions, the
issue tracked is not the best place for discussions.

[1] https://groups.google.com/forum/#!forum/selenium-developers

Reported by barancev on 2013-10-30 18:58:29

  • Labels removed: Status-Untriaged

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Reported by luke.semerau on 2015-09-17 18:18:12

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 4, 2016
@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