简体   繁体   English

如何在Python中使用Splinter自动处理警报

[英]How to automatically handle alerts with Splinter in Python

I am using the Python wrapper for Selenium, Splinter, to make purchases on an online store. 我正在使用Splinter的Selenium Python包装器在网上商店进行购买。 Randomly, the browser throws an UnexpectedAlertPresentException. 浏览器随机地抛出UnexpectedAlertPresentException。 I don't know where in my process this error will be thrown, and it seems ridiculous to check for this alert and dismiss it all the time. 我不知道在我的过程中该错误将被抛出到哪里,并且检查该警报并始终将其消除似乎很荒谬。 Is there a way to specify to the driver that alerts should be automatically dismissed? 有没有一种方法可以向驾驶员指定应自动解除警报?

You can override the window.alert method using browser.execute_script. 您可以使用browser.execute_script覆盖window.alert方法。 See for eg. 参见例如。 http://itreallymatters.net/post/1482786902/testing-webpages-with-javascript-popups-correctly#.VUvFhNS1Gko http://itreallymatters.net/post/1482786902/testing-webpages-with-javascript-popups-正确地#.VUvFhNS1Gko

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM