我试着用CDP做测试,
webdriver.execute_cdp_cmd('Network.enable', {})
与远程网络驱动程序(在Selenoid)。但是得到这个错误:
AttributeError:'WebDriver‘对象没有属性'execute_cdp_cmd’。在当地环境中,它工作得很好。我尝试使用Selenium 3.141.0和4.1.3。
我熟悉PyCDP文档(https://py-cdp.readthedocs.io/en/latest/getting_started.html),但我不知道如何正确使用它。
为什么它不能与远程Why驱动程序一起工作?有人有使用Selenium 4中的python执行CDP命令的例子吗?
我使用以下功能:
capabilities ={ 'loggingPrefs':{'browser':'ALL'},'goog:loggingPrefs':{'performance':'ALL'},"browserName":"chrome","browserVersion":"99.0","selenoid:options":{ "enableVNC":True,"enableVideo":False }}
如果request.config.getoption('--remote'):driver =request.config.getoption desired_capabilities=capabilities,options=options)
发布于 2022-10-12 19:34:36
看起来,远程网络驱动程序不支持CDP。
找到了解决这个问题的好办法:
import json
def send(driver, cmd, params={}):
resource = "/session/%s/chromium/send_command_and_get_result" % driver.session_id
url = driver.command_executor._url + resource
body = json.dumps({'cmd': cmd, 'params': params})
response = driver.command_executor._request('POST', url, body)
return response.get('value')
send(webdriver, 'Network.enable', {})
资料来源和相关讨论:https://github.com/SeleniumHQ/selenium/issues/8672
https://stackoverflow.com/questions/72121479
复制相似问题