Is webdriver capable to run a browser with a faked time, date or time zone?

Such ability would be highly useful for my automation purposes.

Yet, I did not find any such ability in the webdriver documentation. I guess such functionality is quite sophisticated as it would require to intercept and feedback altered Kernel calls. Therefore not necessarily included into webdriver - can you tell me otherwise?

Can you suggest any other method to spoof browser time settings that works with Selenium? I am open for Windows/Linux solutions. Yet this way has to work with webdriver automation.

-Olivier (Indeed a great blend of people here at stackexchange.)

  • What is the test objective you are trying to meet? I'm sceptical of the utility of what you are asking. It suggests you are testing the wrong thing. Selenium is intended for functional system testing. Unit test Javascript with node or similar. stackoverflow.com/questions/300855/… Commented Sep 15, 2017 at 16:03

1 Answer 1


The browser date/time functions are all JavaScript. You should be able to use Sinon.JS or TimeShift.JS to mock the date/time.

  • Inject/Add the mocking framework during tests runs
  • Mock the Date object with the JavaScript Executor
  • Set the timezone
  • Run tests

Now all calls to the internal Date object will return the shifted time.

For examples see this post with TimeShift.JS and something like this is also described in this blog post, although it uses ruby TimeCop for time sync.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.