I think this changed in the spec at some point. The thing is that no such alert, frame and window and stale element reference should return 404 instead of 400. https://w3c.github.io/webdriver/webdriver-spec.html#handling-errors
Created attachment 321533 [details] Patch
Comment on attachment 321533 [details] Patch rs=me
Committed r222703: <http://trac.webkit.org/changeset/222703>
<rdar://problem/34764444>