SafariDriver Immediately Releases Click Events. Does not Check Pending Navigation.
This was reported in 2014 but never triaged/addressed. See Google Code - Open Issues
The issue: After clicking a link / button using SafariDriver, it appears there is no check for pending navigation requests before releasing the click event as complete.
The Consequence: Click actions which result in a page refresh or redirect are released before the refresh/redirect occurs and thus proceeding actions are kicked off too early and fail consistently.
The Workaround: Add element level waits after click-through events to stop SafariDriver from submitting the next actions too early. Downside is the element-wait timeout is being eaten up by page load. Moreover, because the click has been released as successful, any failure is attributed to the next action rather than the click.
The Solution: Have SafariDriver behave similar to ChromeDriver in which pending navigations are checked before releasing the click action. My fear is that there is a good reason why SafariDriver cannot do this, and perhaps this is why the issue was never addressed. If this is the case, it would just be great to understand the limitation and hear if there are better / other workarounds.
Here are some details from the original ticket post to help illustrate the matter.
SafariDriver log:
14:37:57.86 [safaridriver.extension.Server] [779h50wyyvq2] Received a message: {"origin":"webdriver","type":"command","command":{"id":"79","name":"clickElement","parameters":{"id":":wdc:1412681861302"}}}
14:37:57.87 [safaridriver.extension.Server] [779h50wyyvq2] Executing command: clickElement
14:37:57.87 [safaridriver.extension.Tab] [2ymt8tn075fa] Sending message: {"origin":0,"type":"command","command":{"id":"9hv7rx7u2env","name":"clickElement","parameters":{"id":":wdc:1412681861302"}}}
14:37:57.87 [safaridriver.inject._Top_] [p1s4okvij0cl] Executing {"id":"9hv7rx7u2env","name":"clickElement","parameters":{"id":":wdc:1412681861302"}}
14:37:57.88 [safaridriver.extension.Tab] [2ymt8tn075fa] Received response: {"origin":1,"type":"response","id":"9hv7rx7u2env","response":{"status":0,"value":null}}
14:37:57.88 [safaridriver.extension.Server] [779h50wyyvq2] Sending response: {"origin":0,"type":"response","id":"79","response":{"status":0,"value":null}}
ChromeDriver log:
[26.534][INFO]: COMMAND ClickElement {
"id": "0.7670850940048695-14"
}
[26.534][INFO]: Waiting for pending navigations...
[26.534][INFO]: Done waiting for pending navigations
[26.594][INFO]: Waiting for pending navigations...
[38.981][INFO]: Done waiting for pending navigations
[38.981][INFO]: RESPONSE ClickElement
under SafariDriver response for click action is being sent immediately after click but, this click leads to another page and it should send a response when new page loaded(like under ChromeDriver).
Selenium Version: 2.48.2 / 2.49.0 OS Version: Mac OS X Yosemite / El Capitan Browse Version: Safari 9.0 / 9.0.1 / 9.0.2
Safari notifies the extension of page navigations via asynchronous events. When one of these events is received, the driver will wait for the corresponding nav complete event.
If you expect a navigation to occur after a click, and subsequent commands are executing before the browser reports the navigation to the driver, the appropriate action is to change your test to explicitly wait for that navigation to occur.
thanks @jleyba for taking the time to respond and explain. However, I see you closed the issue so is the implication that there is no possibility of an bug/deficiency in this case?
I ask because you note SafariDriver should wait for these events, but you also state it is possible it will not wait and in those cases to 'explicitly wait for that navigation to occur'. It appears I may be missing context into the flows in which SafariDriver will and will not wait.
My goal is to understand more deeply such that I can build a better solution for my platform. I currently employ explicit waits and they do work -- but I strive to know why SafariDriver is failing in scenarios where other webdrivers are not (they do not release the click early). I am primarily concerned for cases where the URL does not change during the navigation event, such as a page refresh or an AJAX redirect (where waiting for element visibility / URL changes are not viable).
If it would help, I am happy to take the time to build a standalone test which highlights the behaviour on a public website. If there is a function to be enhanced, or a bug to be fixed - my intention would be to post a code bounty to aid in speeding up any development.
Best, J
I too see that SafariDriver doesn't wait for navigation to finish, whereas both ChromeDriver and Phantom do.
I have a form that submits to the same URL, and returns to the same URL. The submission (a click event) continues the test immediately without waiting for the page navigation to finish (i.e. waiting for the submit action to complete).
Does this mean I need to litter my tests with if using safari, wait X time? Or a fix for this?
Execution logs are the same, but Safari doesn't wait.
Safari log:
15:10:43.506 INFO - Executing: [click: 7 [[SafariDriver: safari on MAC (null)] -> name: save]])
15:10:43.513 INFO - Done: [click: 7 [[SafariDriver: safari on MAC (null)] -> name: save]]
15:10:43.514 INFO - Executing: [find element: By.xpath: //ul[@class='orangeText']/li[1]])
Chrome:
15:11:55.909 INFO - Executing: [click: 7 [[ChromeDriver: chrome on MAC (...)] -> name: save]])
15:11:56.353 INFO - Done: [click: 7 [[ChromeDriver: chrome on MAC (...)] -> name: save]]
15:11:56.354 INFO - Executing: [find element: By.xpath: //ul[@class='orangeText']/li[1]])
15:11:56.369 INFO - Done: [find element: By.xpath: //ul[@class='orangeText']/li[1]]
It is 2018 and I still see the issue to be present. Is there no fix at all for this?
The issue was raised 2 years ago on the driver implementation developed by Selenium team. It's 2018 and now Apple develops safari driver, issues should be reported to https://bugs.webkit.org/