[英]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.