且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过Selenium WebDriver C#获取HTTP状态代码

更新时间:2022-01-17 05:34:54

不使用外部工具编号

你知道,这在过去已被提出过多次,也是Selenium中最大的问题之一官方问题跟踪器。 特定问题已被反弹,并且基本上认为它超出了Selenium的范围。

You see, this has been brought up a number of times in the past and is one of the largest "issues" within Selenium's official issue tracker. The particular issue has been bounced around and essentially decided that it's outside the scope of Selenium.

然而,这并不意味着它是不可能的。值得庆幸的是,你正在使用C#,所以它比你想象的容易一些。

This however, does not mean that it is not possible. Thankfully, you are using C#, so it's a little easier than you may think.

最近,一位Selenium开发人员撰写了一篇博文,其中概述了确切地说如何在C#中执行此操作。这是一篇由三部分组成的博客文章,帮助解释每个步骤,并使用一个名为 Fiddler 的外部工具(顺便说一下,这是一个很棒的工具) )。

Recently, one of the Selenium developers wrote a blog post outlining exactly how to do this in C#. It is a three part blog post to help explain each step and uses an external tool, called Fiddler (which, by the way, is one awesome tool).

Fiddler是一个代理,有一个C#API,允许你拦截请求。因此,它意味着您可以简单地指出Selenium使用该代理,然后挂钩到Fiddler的API以确切地检查请求的状态代码。

Fiddler is a proxy and has a C# API that allows you to intercept requests. It therefore means you can simply "point" Selenium to use that proxy, and then hook into Fiddler's API to check exactly what status code the request has.

我只是链接到博客文章而不是给你代码,因为在这些帖子中对它进行了彻底的解释。

I am merely linking to the blog post rather than giving you code to this since it's pretty thoroughly explained in those posts.

也许尝试一下,然后如果你在实施他的任何问题时回来设计。顺便提一下,这个人也是***的会员,所以也可以看到你的帖子。

Perhaps try it, and then come back if you get any issues implementing his design. Incidentally the guy is also a member here at ***, so may also see your post.