当用selenium中的get(url)方法打开微博,Chrome弹出通知窗口,导致Selenium语句失效

此篇记录一下学到的解决方法
options = webdriver.ChromeOptions()
prefs = {
'profile.default_content_setting_values':
{
'notifications': 2
}
}
options.add_experimental_option('prefs', prefs)
wb= webdriver.Chrome(chrome_options=options)
wb.get(url)
wb.implicitly_wait(5)
亲测有效!
这篇博客介绍了在使用Selenium的Chrome浏览器驱动时遇到的通知窗口问题及解决方案。通过设置ChromeOptions,禁用通知权限,使得Selenium能够正常运行。具体方法是创建ChromeOptions对象,设置'profile.default_content_setting_values.notifications'为2,然后添加到Chrome驱动器中。
1665

被折叠的 条评论
为什么被折叠?



