Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Can Selenium RC Capture the screenshot by specify sclocator or expath

$
0
0
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.


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());
            }
    }

It's shown Error : com.thoughtworks.selenium.DefaultSelenium cannot be cast to org.openqa.selenium.TakesScreenshot


Best regards

Viewing all articles
Browse latest Browse all 4756

Trending Articles