How do I enable geolocation support in chromedriver?

前端 未结 7 595
日久生厌
日久生厌 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:48

    In the known issues section of the chromedriver wiki they said that you Cannot specify a custom profile

    This is why it seems to me that @Sotomajor answer about using profile with Chrome as you would do with firefox will not work.

    In one of my integration tests I faced the same issue. But because I was not bothering about the real geolocation values, all I had to do is to mock window.navigator.gelocation

    In you java test code put this workaround to avoid Chrome geoloc permission info bar.

    chromeDriver.executeScript("window.navigator.geolocation.getCurrentPosition = 
        function(success){
             var position = {"coords" : {
                                           "latitude": "555", 
                                           "longitude": "999"
                                         }
                             }; 
             success(position);}");
    

    latitude (555) and longitude (999) values here are just test value

    0 讨论(0)
提交回复
热议问题