如果是不创建新浏览器窗口,直接在已打开的浏览器,则代码需要修改为:
caps = DesiredCapabilities.CHROME
caps['loggingPrefs'] = {'performance': 'ALL'}
options = webdriver.ChromeOptions()
options.add_experimental_option('w3c', False)
options.add_experimental_option("debuggerAddress", "127.0.0.1:9527")
driver = webdriver.Chrome(options=options, desired_capabilities=caps)