How do I enable geolocation support in chromedriver?

前端 未结 7 596
日久生厌
日久生厌 2020-11-30 08:08

I need to test a JS geolocation functionality with Selenium and I am using chromedriver to run the test on the latest Chrome.

The problem is now that Chrome prompts

7条回答
  •  失恋的感觉
    2020-11-30 08:31

    The simplest to set geoLocation is to just naviaget on that url and click on allow location by selenium. Here is the code for refrence

     driver.navigate().to("chrome://settings/content");
        driver.switchTo().frame("settings");
        WebElement location= driver.findElement(By.xpath("//*[@name='location' and @value='allow']"));
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ((JavascriptExecutor) driver).executeScript("arguments[0].click();", location);
         WebElement done= driver.findElement(By.xpath(""));
    
        driver.findElement(By.xpath("//*[@id='content-settings-overlay-confirm']")).click();
    
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        driver.navigate().to("url");
    

提交回复
热议问题