Dealing with Captcha images
I see from some of the forum posts that it is possible to throw up a dialogue box with the captcha image showing to allow a user to manually enter the captcha information.
My Java skills are weak, does anyone have a sample script they are willing to share?
Thank you
Thanks for the help, I'll try this.
captcha input script
i wrote a quick script that should accomplish what you want to do. To use this you will need a session variable named CAPTCHA_URL with the url of the image. It then will save your input into a session variable named CAPTCHA_TEXT.
// Output: CAPTCHA_TEXT session variable
/*takes the session variable CAPTCHA_URL, generates a user input window, then saves the output to CAPTCHA_TEXT*/
import javax.swing.BoxLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.JLabel;
//create an action listener
ActionListener buttonListener = new ActionListener() {
actionPerformed( event ) {
session.setVariable("WAIT", "false");
session.setVariable("CAPTCHA_TEXT", input.getText());
captchaFrame.setVisible(false);
captchaFrame.dispose();
}
};
session.setVariable("WAIT", "true");
session.downloadFile(session.getVariable("CAPTCHA_URL"), "captcha_file");
//create our components for the window
iconlabel = new JLabel (new ImageIcon("captcha_file"));
JFrame captchaFrame = new JFrame("Captcha");
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JTextField input = new JTextField();
JButton button = new JButton("OK");
button.setAlignmentX(Component.CENTER_ALIGNMENT);
//add all of the components to the window
panel.add(iconlabel);
panel.add(input);
panel.add(button);
captchaFrame.add(panel);
button.addActionListener(buttonListener);
captchaFrame.pack();
captchaFrame.setVisible(true);
//pause the until the ok button is pressed
while(session.getVariable("WAIT").equals("true"))
{
session.pause(1000);
}