简体   繁体   English

如何使用 selenium webdriver 和 python 关闭 chrome 浏览器弹出对话框

[英]how to close chrome browser popup dialog using selenium webdriver and python

I have a python code that uses selenium webdriver (along with chromedriver), to log into facebook and take a screenshot of the page.我有一个 python 代码,它使用 selenium webdriver(以及 chromedriver)登录到 facebook 并截取页面的屏幕截图。
the script itself works as expected, however, after logging in, chrome browser shows a dialog regarding facebook notifications ( Chrome Popup )脚本本身按预期工作,但是,登录后,chrome 浏览器会显示一个关于 facebook 通知的对话框( Chrome 弹出窗口)

The dialog seems to be generated by the browser, not the page itself.该对话框似乎是由浏览器生成的,而不是页面本身。
i'm unable to identify and capture the element or use "switch to alert" method.我无法识别和捕获元素或使用“切换到警报”方法。

How can i interact with this dialog (either Allow, Dismiss or close it)?我如何与此对话框交互(允许、关闭或关闭它)?

Thanks!谢谢!

in Python you can use在 Python 中你可以使用

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-notifications")
webdriver.Chrome(os.path.join(path, 'chromedriver'),
                 chrome_options=chrome_options)

You can try with launching the chrome browser with disabled pop-ups (browser pop-ups).您可以尝试启动带有禁用弹出窗口(浏览器弹出窗口)的 chrome 浏览器。 The following code snippet is in Java.以下代码片段使用 Java。 It will be somewhat similar in python i believe.我相信它在 python 中会有些相似。

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-popup-blocking");
options.addArguments("test-type");
ChromeDriver driver = new ChromeDriver(options);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Selenium Webdriver 在 Chrome 中关闭下载弹出窗口? - How to close download popup in Chrome using Selenium Webdriver? 如何使用python硒关闭另一个Chrome弹出窗口 - How to close yet another chrome popup using python selenium 如何使用Selenium WebDriver和python打开功能齐全的Chrome浏览器? - How to open a fully functioning chrome browser using selenium WebDriver with python? 关闭Selenium Python中的浏览器弹出窗口 - Close browser popup in Selenium Python 如何在 selenium webdriver(python)中禁用 chrome 的“保存密码”弹出窗口 - How to disable chrome's "save password" popup in selenium webdriver (python) 如何在 python 中的 selenium webdriver 中禁用 chrome 通知弹出窗口 - how to disable chrome notifications popup in selenium webdriver in python 如何在Python中使用Selenium在由不同WebDriver打开的不同Chrome浏览器窗口之间切换? - How to switch between different chrome browser window opened by different WebDriver using selenium in Python? 由python webdriver在chrome浏览器中的selenium新选项卡 - selenium new tab in chrome browser by python webdriver 如何使用python处理Selenium WebDriver的身份验证弹出窗口? - How to handle authentication popup with Selenium WebDriver using python? 使用 Selenium Webdriver Python 的身份验证弹出窗口 - Authentication Popup using Selenium Webdriver Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM