无法模拟自动浏览器的位置:pytest、selenium

问题描述 投票:0回答:1

我正在使用 selenium、pytest、splinter 和 gherkins,

我有一个测试用例,我想模拟浏览器的实际位置和时区。

我尝试了很多方法,例如执行js脚本和模拟开发工具方法。但对我来说没有任何作用。有谁知道他们这样做的想法或例子吗?

selenium-webdriver pytest splinter
1个回答
0
投票

以下代码成功设置网络驱动程序的位置和时区 --

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
© www.soinside.com 2019 - 2024. All rights reserved.