簡體   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