I have code made in selenium webdriver Java using HTML Unit driver I am inputting various fields in that program.
My question is Which language should I use in order to get captcha displayed on the web page opened by HTML unit driver.what I want is that a window should pop up to the user, on this window captcha should be displayed which was opened by html unit driver also this window will also have a text field to input that captcha also, this input field will be linked with webpage's input field of captcha which is currently being processed by html unit driver and once the captcha has been entered by the user rest of the selenium code should be executed.
Initially, I was thinking of using jsoup to get captcha and display it to user but that is not working because both selenium and jsoup are picking different captchas as they start a new connection.
My earlier code was like this
System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("URL abc");
Connection conn = Jsoup.connect("URL abc");
Document d = conn.get();
Element captcha = d.select("#cimage").first();
if (captcha == null) {
throw new RuntimeException("Unable to find captcha...");
}
// Fetch the captcha image
Connection.Response response = Jsoup //
.connect(captcha.absUrl("src")) // Extract image absolute URL
.cookies(conn.response().cookies()) // Grab cookies
.ignoreContentType(true) // Needed for fetching image
.execute();
// Load image from Jsoup response
ImageIcon image = new ImageIcon(ImageIO.read(new ByteArrayInputStream(response.bodyAsBytes())));
// Show image
JOptionPane.showMessageDialog(null, image, "Captcha image", JOptionPane.PLAIN_MESSAGE);
Using chrome driver I am getting two different captchas probably because both selenium and jsoup are starting a new connection Below is the image for the same
Any suggestion or examples would be immensely appreciated. Please let me know if any additional information is needed!