【问题标题】:AttributeError: 'WebDriver' object has no attribute 'execute_cdp_cmd'AttributeError:“WebDriver”对象没有属性“execute_cdp_cmd”
【发布时间】:2021-06-23 07:38:18
【问题描述】:

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

我正在使用 selenium==4.0.0b2

我正在运行 remote 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)

我错过了什么??

【问题讨论】:

  • 如何声明驱动程序?
  • 我就是这样声明驱动的

标签: python python-3.x selenium selenium-chromedriver selenium4


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2022-10-13
    • 1970-01-01
    • 2022-06-29
    • 2022-06-25
    • 2022-11-19
    • 2023-01-07
    • 2016-10-14
    • 2021-05-24
    • 2022-09-29
    相关资源
    最近更新 更多