在selenium.py中,如何处理404状态码
我正在用 python 编写一个 selenium 脚本。我发现,当 selenium 收到 404 状态代码时。它崩溃了。最好的处理方法是什么?
I'm writing a selenium script by python. Something that I found out, is that when selenium gets 404 status code. it crashes. What is the best way to deal with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有类似的问题。有时,我们在整个测试过程中使用的服务器(即,不是我们测试的主服务器,只是“子服务器”)会崩溃。我添加了一个小的健全性测试,以查看服务器在主要测试运行之前是否已启动。也就是说,我向服务器执行了一个简单的 GET 请求,并用 try-catch 包围它,如果通过了,我将继续测试。让我强调这一点——在我开始使用 selenium 之前,我会使用 python 的 urllib2 执行 GET 请求。这不是最好的解决方案,但速度很快,对我来说已经足够了。
I had a similar problem. Sometimes a server we were using (i.e., not the main server we were testing, only a "sub-server") throughout our tests would crash. I added a minor sanity test to see if the server is up or not before the main tests ran. That is, I performed a simple GET request to the server, surrounded it with try-catch and if that passed I continue with the tests. Let me stress out this point- before i even started selenium i would perform a GET request using python's urllib2. It's not the best of solutions but it's fast it was enough for me.