我想用一个伪造的GPS坐标在chromedriver上测试该程序,然后我通过开发人员的方式进行了测试-更多工具-传感器,设置了“地理位置覆盖”。问题是程序无法正常工作。有人吗?有帮助的想法吗?
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from config.settings import BASE_PATH
import os
class FakeLocation(object):
def __init__(self):
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("proxy-server=http://127.0.0.1:1087")
prefs = {
'profile.default_content_setting_values':
{
'notifications': 1,
'geolocation': 1
},
'devtools.preferences': {
'emulation.geolocationOverride': "\"11.111698@-122.222954:\"",
},
'profile.content_settings.exceptions.geolocation':{
'BaseUrls.Root.AbsoluteUri': {
'last_modified': '13160237885099795',
'setting': '1'
}
},
'profile.geolocation.default_content_setting': 1
}
chromeOptions.add_experimental_option('prefs', prefs)
chromedriver_path = os.path.join(BASE_PATH, 'utils/driver/chromedriver')
log_path = os.path.join(BASE_PATH, 'utils/driver/test.log')
self.driver = webdriver.Chrome(executable_path=chromedriver_path, chrome_options=chromeOptions, service_log_path=log_path)
def run(self):
self.driver.get("file:///Users/a/Desktop/location.html")
if __name__ == "__main__":
obj = FakeLocation()
obj.run()
我希望地理定位的输出被覆盖。