1

I am trying this below code,

package wayPoint;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import javax.imageio.ImageIO;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.Test;

import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.comparison.ImageDiff;
import ru.yandex.qatools.ashot.comparison.ImageDiffer;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;


public class imageCompare {
    @Test
    public void ImageComparison() throws IOException, InterruptedException{
          //System.setProperty("webdriver.chrome.driver","write here path of chromedriver exe file");
        DesiredCapabilities dc = new DesiredCapabilities();
        dc.setCapability("marionette", false);
        //FirefoxProfile fp = new FirefoxProfile();
        WebDriver driver=new ChromeDriver(dc);

        driver.manage().timeouts().implicitlyWait(150,TimeUnit.SECONDS);

        driver.get("URL");
        driver.findElement(By.id("j_username")).sendKeys("userName");
        driver.findElement(By.id("j_password")).sendKeys("password");
        driver.findElement(By.name("Submit")).click();
        driver.navigate().to("URL2");

        WebElement webElement = driver.findElement(By.xpath(".//*[@id='OL_Icon_618_innerImage']"));

        System.out.println("value= "+webElement);


        BufferedImage expectedImage = ImageIO.read(new File("/home/neha/neha/screenshotsByCode/mm_20_red.png"));

        System.out.println("\n expectedImage= "+expectedImage );
        Thread.sleep(5000);

        Screenshot scrnshot = new AShot().takeScreenshot(driver, webElement);

        ImageIO.write(scrnshot.getImage(),"PNG", new File("/home/neha/neha/screenshotsByCode/image.png"));

        BufferedImage actualImage = scrnshot.getImage();

        ImageDiffer imgDiff = new ImageDiffer();

        ImageDiff diff = imgDiff.makeDiff(expectedImage,actualImage);

        System.out.println("finally");
        Assert.assertTrue(diff.equals(diff), "Images are Same");
    }

}

But found exception that,

FAILED: ImageComparison
org.openqa.selenium.WebDriverException: unknown error: el.offset is not a function
  (Session info: chrome=58.0.3029.96)
  (Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.4.0-31-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13 milliseconds
Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700'
System info: host: 'neha', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-31-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac), userDataDir=/tmp/.org.chromium.Chromium.5mBoy6}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.96, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
  • I met with the same problem. org.openqa.selenium.WebDriverException: unknown error: el.offset is not a function – Zhigang Aug 3 '17 at 8:34
  • I faced the same problem. Somebody know how to resolve it? – Alex Gonchar Aug 18 '17 at 8:26

protected by Bharat Mane Aug 18 '17 at 12:16

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Browse other questions tagged or ask your own question.