Hi,
Can selenium RC take the screenshot by specify element such as (xpath or sclocator) instead of take the screenshot whole page.
Environments
- Selenium RC with user-extension.js (SmartClient 9.1)
- Browser IE9
I'm using this code but not working.
It's shown Error : com.thoughtworks.selenium.DefaultSelenium cannot be cast to org.openqa.selenium.TakesScreenshot
Best regards
Can selenium RC take the screenshot by specify element such as (xpath or sclocator) instead of take the screenshot whole page.
Environments
- Selenium RC with user-extension.js (SmartClient 9.1)
- Browser IE9
I'm using this code but not working.
Code:
public void TakeScreenShotByElement(String locator, String fileName) {
try {
File screen = ((TakesScreenshot) selenium).getScreenshotAs(OutputType.FILE);
int getHeight = (Integer) selenium.getElementHeight(locator);
int getWidth = (Integer) selenium.getElementWidth(locator);
int getX = (Integer) selenium.getElementPositionLeft(locator);
int getY = (Integer) selenium.getElementPositionTop(locator);
BufferedImage img = null;
img = ImageIO.read(screen);
BufferedImage dest = img.getSubimage(getX, getY, getWidth, getHeight);
ImageIO.write(dest, "png", screen);
File f = null;
f = new File("D:\\TestScreenshot\\Selenium\\Projects\\UI\\Screenshots\\"+fileName+".png");
FileUtils.copyFile(screen, f);
} catch (Exception e) {
System.out.println("Error : " +e.getMessage());
}
}Best regards