AttributeError: 'WebDriver' 对象没有属性 'execute_cdp_cmd'

问题描述

我正在尝试根据此文档设置地理位置: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 你可以试试看。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...