1. This website uses cookies to improve service and provide a tailored user experience. By using this site, you agree to this use. See our Cookie Policy.
    Dismiss Notice

Fake system time in Selenium Chromedriver

Discussion in 'General Scripting Chat' started by missx, Jun 22, 2017.

  1. missx

    missx Newbie

    Jun 13, 2015
    Likes Received:
    Hi, I'm trying to fake the system time when using Chromedriver, tried everything, nothing works and I'm out of ideas. I'm using Chromedriver as a lib in java and checking if the system time is faked at whoer.net. I want whoer to show the system time equal to local time (which I can know by my proxie's ip). Now whoer keeps showing my Windows time at the "System time" field, no matter what I do.

    Wht did I try:

    1. Adding some chrome options

    chromeOptions.put("args", Arrays.asList("--lang=en", "--disable-web-security", "--disable-local-storage",
                    "--disable-system-timezone-automatic-detection", "--disable-webgl", "--dns-prefetch-disable",
                    "--disable-plugins-discovery", "--local-timezone", "--disable-timezone-tracking-option",
    2. Setting system property

    System.setProperty("user.timezone", "GMT");
    3. Injecting Javascript

    ((JavascriptExecutor) driver).executeScript("var d = new Date(2012, 0, 20); Date = undefined; Date = function(){return d;}");
    And another variant of javascript

    ((JavascriptExecutor) driver).executeScript("var dateYouWant = 1363798981693; Date.prototype.getTime = function() { return dateYouWant; }; console.log( (new Date).getTime() );");
    4. Setting Windows system time via cmd:

    Runtime.getRuntime().exec("cmd /C time " + "16:56:10");
    Only variant #4 worked but it's useless for me since I want to make a multithreaded bot with many instances of Chromedriver each one with different system time.

    Don't understand at all why javascript injection doesn't work.

    Please help. How to fake the system time?