问题描述
我正在尝试根据此文档设置地理位置:https://www.selenium.dev/documentation/en/support_packages/chrome_devtools/
我正在使用 selenium==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)
我错过了什么??
解决方法
我也有这个问题。但是我在 Visual Studio 中使用的是 VB.NET 找不到任何 Chrome Devtool。 最后我发现了一个 nuget 是 https://github.com/ToCSharp/AsyncChromeDriver 你可以试试看。