繁体   English   中英

使用selenium.open()打开带有参数的URL

[英]Open a URL with parameters using selenium.open()

我正在使用selenium.open()打开一个URL,该URL将cookie输出打印到浏览器窗口中:

String cookiestr = "http://my.server.com/cookie?out=text";
selenium.open( cookiestr );

问题是,它打开一个“另存为...”弹出窗口,以保存名为“ cookie”的文件。 当我直接在浏览器中打开相同的URL时,它会在浏览器窗口中显示文本。

当我打开URL时,我想捕获显示的正文,但无法这样做。 还有其他可用的命令可以用来执行此操作吗?

BufferedWriter outputfile = null;
String bodytext = selenium.getBodyText();
System.out.println("Body Text  :" + bodytext);
Integer I = new Integer(i);
filename = "C:\\cookies\\" + I.toString() + ".txt";
outputfile = new BufferedWriter(new FileWriter( filename ));
outputfile.write( bodytext );
outputfile.newLine();
i++;

您的cookie servlet应该设置内容类型:

response.setContentType("text/plain");

暂无
暂无

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

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