我不知道如何設置使用Chromedriver時區。是否有一些ChromeOptions參數或什麼?我到處搜索,沒有找到。如何在Selenium Chromedriver中設置時區?
問題是,當我去一些網站(例如,https://whoer.net)時,它顯示的系統時間等於在Windows上設置的時間。我希望能夠以某種方式改變Chromedriver的時區來執行時區相關測試。
我試圖設置一些瀏覽器選項:
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);
它不工作。
試圖做使用Javascript一些奇怪的事情:
((JavascriptExecutor) driver).executeScript("Date.prototype.getTime = function() { return 1 };");
它沒有幫助。
編輯:
發現這個https://sqa.stackexchange.com/questions/8838/faking-system-time-date-with-selenium-webdriver
試過從TimeShift.js複製這樣的代碼頁上執行JavaScript的:在https://whoer.net
((JavascriptExecutor) driver).executeScript("/*code from TimeShift.js here*/ TimeShift.setTimezoneOffset(-60);");
系統時間沒有改變。我究竟做錯了什麼?
它將始終顯示在Windows上設置的時間。在Windows上更改時間。 –
也許這個類似的問題可以幫你https://stackoverflow.com/questions/35848043/selenium-scraping-changing-timezone –
@ Pv-Viana在這個問題,他是從一些網站刮一個時區,然後他可以選擇所需時區來自網站的菜單。這不一樣。 – Helen