Код: Выделить всё
ChromiumDriver driver = new ChromeDriver(); //Initializing the Chrome driver
driver.manage().window().maximize(); //Maximizing the browser to make it fullscreen
DevTools devTools = driver.getDevTools();//getting thedevtools object from the driver
devTools.createSession();//Creating a devTool session
Map place = new HashMap();//Creating a map with geolocation data
place.put("latitude", 19);
place.put("longitude", 73);
place.put("accuracy", 1);
driver.executeCdpCommand("Emulation.setGeolocationOverride", place);//This is suppose to override the browser's current geolocation to Navi Mumbai's one as latitude 19 and longitude 73 is for Navi Mumbai
driver.get("https:google.com");
driver.findElement(By.name("q")).sendKeys("Places near me", Keys.ENTER);//Entering places near me in google search and click on enter
System.out.println(driver.findElement(By.xpath("//span[text()='Results for ']/following-sibling::span[2]")).getText());//This should fetch place that is currently overridden in the browser, but it is still fetching me my current location
Я пытался обновить страницу, а также пробовал использовать браузер Edge, поскольку он также является браузером на основе Chrome и обнаружил, что даже Edge возвращает мое текущее местоположение, а не переопределяет местоположение, которое я указал в параметрах.
Подробнее здесь: https://stackoverflow.com/questions/788 ... ocation-in