I'm using selenium-webdriver with nodejs to scrap a page. One element of the page is a captcha that i want to grab the image. I've been searching but i only found java or python codes to do that.
So far i got:
function writeScreenshot(data, name) {
name = name || 'ss.png';
var screenshotPath = '/Users/Projects/screenshots/';
fs.writeFileSync(screenshotPath + name, data, 'base64');
};
driver.takeScreenshot().then(function(data) {
writeScreenshot(data, 'out1.png');
});
//location of captcha
var capt = driver.findElement(webdriver.By.xpath('myXPath');
var location = capt.getLocation();
var captAltura = capt.getSize().getHeight();
var captLargura = capt.getSize().getWidth();
The screenshot of the page is working. The second part where "//location of captcha" is set i'm not sure because i do not know how to proceed. How can i crop the image?
-- Update (Html code):
<form name="form" method="POST">
<table width="750" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr bgcolor="#CCCCCC">
<td width="100%" height="31" align="center">
<font class="code">Code:</font>
<input type="text" name="captcha" size="4" maxlength="4" value="" title="Security Code" class="inputcaptcha" onclick="this.select()">
<img src="captcha.php" width="90" align="middle">
</td>
</tr>
</tbody>
</table>
</form>