我正在使用 selenium、pytest、splinter 和 gherkins,
我有一个测试用例,我想模拟浏览器的实际位置和时区。
我尝试了很多方法,例如执行js脚本和模拟开发工具方法。但对我来说没有任何作用。有谁知道他们这样做的想法或例子吗?
以下代码成功设置网络驱动程序的位置和时区 --
from selenium import webdriver
class Params:
LOCATION = {
"latitude": 25.2048,
"longitude": 55.2708,
"accuracy": 100,
}
TIMEZONE = {
"timezoneId": "America/New_York"
}
driver = webdriver.Chrome()
driver.execute_cdp_cmd("Emulation.setGeolocationOverride", Params.LOCATION)
driver.execute_cdp_cmd("Emulation.setTimezoneOverride", Params.TIMEZONE)
driver.get("https://my-location.org/") # Verify location
driver.get("https://webbrowsertools.com/timezone/") # Verify timezone