使用Selenium WebDriver检查HttpResponse OK(200) [英] Checking HttpResponse OK (200) with Selenium WebDriver

查看:362
本文介绍了使用Selenium WebDriver检查HttpResponse OK(200)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium Remote WebDriver.我从csv文件中读取了所有链接,并对这些链接进行测试.但有时我会收到404响应.

I am using Selenium Remote WebDriver. I read all links from csv file and run test against those links. But sometimes I get 404 response.

Selenium WebDriver中有什么方法可以检查我们是否收到HTTP响应200?

Is there any way in Selenium WebDriver to check that we get HTTP response 200?

推荐答案

无法直接在WebDriver API中获取HTTP状态代码.这是长期提供的功能请求永远不会实现项目.解决此问题的正确方法是将浏览器配置为使用代理,该代理可以拦截和记录网络流量,并让您的代码查询该代理以获取您所追求的结果.

There is no way to get HTTP status codes directly in the WebDriver API. It has been a long-standing feature request, which will likely never be implemented in the project. The correct solution to your problem is to configure your browser to use a proxy which can intercept and log the network traffic, and have your code query that proxy for he result you're after.

当然,如果您只想检查链接以确保它返回200状态代码,则可以轻松使用HTTP客户端库,无论使用哪种语言,您都可以导航到该链接.除非您需要以某种方式操纵结果页面,否则无需使用WebDriver.

Of course, if all you are interested in is checking a link to make sure it returns a 200 status code, you could easily just use an HTTP client library in whatever language you desire to navigate to the link. There's no need to use WebDriver unless you need to manipulate the resulting page in some way.

这篇关于使用Selenium WebDriver检查HttpResponse OK(200)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆