0

我正在尝试根据此文档设置地理位置:https ://www.selenium.dev/documentation/en/support_packages/chrome_devtools/

我正在使用硒==4.0.0b2

我正在运行远程 webdriver而不是本地,我收到以下错误:

AttributeError: 'WebDriver' object has no attribute 'execute_cdp_cmd'

这是我的示例代码:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium import webdriver
import time

driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    desired_capabilities=DesiredCapabilities.CHROME
)
    Map_coordinates = dict({
            "latitude": 21.841,
            "longitude": -97.948,
            "accuracy": 100
        })

print(Map_coordinates)
driver.execute_cdp_cmd("Emulation.setGeolocationOverride", Map_coordinates)

driver.get('http://www.google.com/')
time.sleep(50)

我错过了什么??

4

1 回答 1

0

我也有这个问题。但我在 Visual Studio 中使用的是 VB.NET,找不到任何 Chrome Devtool。最后我找到了一个 nuget 就是 https://github.com/ToCSharp/AsyncChromeDriver 你可以试试看。

于 2021-05-19T15:27:00.777 回答