i am trying to capture the captcha image from a web page using the following code
WebElement captchaEl = driver.findElement(By.id("captchaLogin"));
//System.out.println("Captcha: "+ source);
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
BufferedImage fullImg = ImageIO.read(screenshot);
Point point = captchaEl.getLocation();
int eleX = point.getX();
int eleY = point.getY();
int eleWidth = captchaEl.getSize().getWidth();
int eleHeight = captchaEl.getSize().getHeight();
BufferedImage eleScreenshot= fullImg.getSubimage(eleX, eleY, eleWidth, eleHeight);
ImageIO.write(eleScreenshot, "png", screenshot);
FileUtils.copyFile(screenshot, new File(outputFileName));
It ends up capturing some other portion in the page, rather than the captcha image. Although it works if phantomjs driver is used, but doesn't work if chromedriver or geckodriver(firefoxdriver) is used. What could be the problem here?