I'm struggling to set a specific timezone while using Chromedriver. Is there an argument in ChromeOptions that can help with this?
The problem arises when I visit certain websites (such as ), where it displays the system time based on Windows settings. I'd like to be able to adjust the Chromedriver's timezone for testing purposes.
I've attempted setting some chrome options:
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("args", Arrays.asList("--disable-system-timezone-automatic-detection", "--local-timezone"));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
Unfortunately, this approach hasn't worked.
I also tried a non-traditional method using Javascript:
((JavascriptExecutor) driver).executeScript("Date.prototype.getTime = function() { return 1 };");
However, this didn't yield the desired result either.
UPDATE:
I came across this resource
I attempted to run javascript on the page using code from TimeShift.js like so:
((JavascriptExecutor) driver).executeScript("/*code from TimeShift.js here*/ TimeShift.setTimezoneOffset(-60);");
Despite this effort, the system time at remained unchanged. What could be the issue here?