获取 Selenium 请求、响应

发布于 2024-09-17 16:53:20 字数 1139 浏览 5 评论 0原文

我尝试了下面的代码,但未捕获请求/响应?

String trafficOutput = selenium.captureNetworkTraffic("xml");
selenium.type("q", "selenium rc");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");

selenium.open("/#hl=en&source=hp&q=selenium+rc&btnG=Google
        +Search&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=ff64793e1cab64b9");
selenium.click("//ol[@id='rso']/li[1]/h3/a/em");
selenium.waitForPageToLoad("30000");
selenium.click("link=Selenium Core");
selenium.waitForPageToLoad("30000");
selenium.click("link=our documentation");
selenium.waitForPageToLoad("30000");
selenium.click("link=Projects");
selenium.waitForPageToLoad("30000");
// assertTrue(selenium.isTextPresent("Results * for selenium rc"));

String resposneText = selenium.getHtmlSource();
DataOutputStream  dos = new DataOutputStream(new FileOutputStream("output", true));

System.out.println("value is-------- "+trafficOutput);
System.out.println("val is "+resposneText);

dos.writeBytes(trafficOutput);
dos.close();

但在这种情况下没有请求/响应?

获得价值

System.out.println("val is " + resposneText);

I tried the below code but req/response is not captured??

String trafficOutput = selenium.captureNetworkTraffic("xml");
selenium.type("q", "selenium rc");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");

selenium.open("/#hl=en&source=hp&q=selenium+rc&btnG=Google
        +Search&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=ff64793e1cab64b9");
selenium.click("//ol[@id='rso']/li[1]/h3/a/em");
selenium.waitForPageToLoad("30000");
selenium.click("link=Selenium Core");
selenium.waitForPageToLoad("30000");
selenium.click("link=our documentation");
selenium.waitForPageToLoad("30000");
selenium.click("link=Projects");
selenium.waitForPageToLoad("30000");
// assertTrue(selenium.isTextPresent("Results * for selenium rc"));

String resposneText = selenium.getHtmlSource();
DataOutputStream  dos = new DataOutputStream(new FileOutputStream("output", true));

System.out.println("value is-------- "+trafficOutput);
System.out.println("val is "+resposneText);

dos.writeBytes(trafficOutput);
dos.close();

But no req/response in this case?

Getting value for

System.out.println("val is " + resposneText);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失而复得 2024-09-24 16:53:20

captureNetworkTraffic 将返回通过 Selenium Remote Control 的流量。当您调用它时,您将获得已发生的流量日志。这可能是您想要的,但如果您想测试 JavaScript,那么可能值得使用 jsTestDriver 之类的东西。

当您调用 getHTMLSource() 时,它将返回页面上或 selenium 当前所在框架中的所有 HTML,返回到测试。然后您可以使用 HTML 进行其他测试。

captureNetworkTraffic will return the traffic that has passed through Selenium Remote Control. When you call it you will get the log of traffic that has occured. This is probably what you want but if you want to be testing JavaScript it might be worth using something like jsTestDriver.

When you call getHTMLSource() it will return all the HTML that is on the page, or in the frame selenium is currently in, back to the test. You can then do other tests with the HTML.

酷到爆炸 2024-09-24 16:53:20

我不知道您是否还需要答案,但是在您完成某些操作后必须调用 captureNetworkTraffic 。您必须执行 selenium.start("captureNetworkTraffic=true") ,它将告诉服务器开始捕获,完成所有导航,然后调用 selenium.captureNetworkTraffic("xml")。然后您将获得数据,但据我所知,它不会捕获响应,而只会捕获请求。

I don't know if you still need an answer, but captureNetworkTraffic has to be called after you have done something. You have to do a selenium.start("captureNetworkTraffic=true") which will tell the server to start capturing, do all of your navigation and then call selenium.captureNetworkTraffic("xml"). Then you will have data, but from what I have seen it doesn't capture responses, just Requests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文