selenium(python)的chrome虚拟定位解决方案

selenium很好用但是chrome的虚拟定位(传感器)一直找不到接口


最后使用了chrome的devtools解决

 

参考的是:

https://stackoverflow.com/questions/69725880/override-geolocation-using-robot-framework-and-seleniumlib

browser = webdriver.Chrome("./chromedriver.exe")

Map_coordinates = dict({
        "latitude": 20,
        "longitude": 110,
        "accuracy": 100
        })
browser.execute_cdp_cmd("Emulation.setGeolocationOverride", Map_coordinates)

具体协议在:

https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setGeolocationOverride

posted @ 2022-03-15 09:05  parallelarc  阅读(482)  评论(0)    收藏  举报