Tec*_*ary 7 python selenium-chromedriver selenium-webdriver
我想将一组所需的功能转换为 selenium Python 中的选项。在下面的代码中,我想找到dc["goog:loggingPrefs"] = {"browser":"INFO"}
与 selenium python 中的选项等效的内容。
我查看过: https: //peter.sh/experiments/chromium-command-line-switches/ 查看是否有等效的loggingPrefs选项开关,但似乎没有。下面的代码适用于 Selenium 4.7.2,但问题是,如果我们更新到 Selenium 4.10(最新),当作为关键字参数传递给 webdriver 时,将不再支持desired_capability。据我所知,大多数基本的所需功能都由浏览器版本、名称等选项支持。我们如何将loggingPrefs所需的功能转换为selenium webdriver的选项。
def printConsoleLogs():
options = Options()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
#includes INFO level console messages, otherwise only SEVERE show
dc = DesiredCapabilities.CHROME.copy()
dc["goog:loggingPrefs"] = {"browser":"INFO"}
driver = webdriver.Chrome(service=service, options=options, desired_capabilities=dc)
driver.get("http://www.thepools.com")
time.sleep(5)
for entry in driver.get_log('browser'):
print(entry)
Run Code Online (Sandbox Code Playgroud)
编辑,找到解决方案,留给将来寻找相同答案的人:
使用options.set_capability("goog:loggingPrefs", {browser: "INFO"})
.set_capability(name, value),允许您将所需的功能转换为硒选项
| 归档时间: |
|
| 查看次数: |
2154 次 |
| 最近记录: |