0

I am using selenium.open(), to open a URL, which prints the cookie output to the browser window:

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

The problem is that, it opens a "Save As..." popup, to save the file named "cookie". When I open the same URL in my browser directly, it displays text in the browser window.

I want to capture the body text shown, when I open the URL, but am unable to do so. Is there any other command available which I can use to do this?

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++;

1 Answer 1

1

your cookie servlet should set content type:

response.setContentType("text/plain");
Sign up to request clarification or add additional context in comments.

2 Comments

hi! thanks for the answer. but I am a bit new to Selenium and Java, would it be apt to ask, where do i put this string? before I call the open() or elsewhere?
is the server controlled by you? If yes - put this in the code where you serve the text file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.