Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting WebDriverException when using AShot in my project to capture a webelement #41

Closed
abhishekkyd opened this issue Jul 4, 2015 · 3 comments

Comments

@abhishekkyd
Copy link

Hi AShot Team,

When I am executing below Java program, I am getting WebDriver Exception for takescreenshot method. Please look into the issue and help me to resolve this. I am using AShot version 1.4.12

System.setProperty("webdriver.chrome.driver",
                "src/main/resources/drivers/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();

        driver.get("http://www.bbc.com");
        Thread.sleep(10000);

        WebElement element = driver
                .findElement(By.cssSelector("#worldService"));

        final Screenshot screenshot = new AShot().shootingStrategy(
                new ViewportPastingStrategy(500)).takeScreenshot(driver,
                element);
        final BufferedImage image = screenshot.getImage();
        ImageIO.write(image, "PNG", new File(System.getProperty("user.home")
                + "/Documents/AShot_BBC_WebElement.png"));

        driver.quit();

Exception:

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: undefined is not a function
  (Session info: chrome=43.0.2357.81)
  (Driver info: chromedriver=2.15.322455 (ae8db840dac8d0c453355d3d922c91adfb61df8f),platform=Mac OS X 10.10.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6 milliseconds
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26'
System info: host: 'Abhisheks-MacBook-Pro.local', ip: '192.168.1.34', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.7.0_79'
Session ID: 3282b4dba0e5dfaf74c935d511ab485e
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/fm/thrpfvws2dj9kglbtz3278wstl_32s/T/.org.chromium.Chromium.F8GFJ2}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=43.0.2357.81, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:508)
    at ru.yandex.qatools.ashot.util.JsCoords.findCoordsWithJquery(JsCoords.java:26)
    at ru.yandex.qatools.ashot.coordinates.JqueryCoordsProvider.ofElement(JqueryCoordsProvider.java:13)
    at ru.yandex.qatools.ashot.coordinates.CoordsProvider.ofElements(CoordsProvider.java:21)
    at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:138)
    at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:155)
    at com.tribune.uiautomation.testscripts.AShotTestEntirePage.main(AShotTestEntirePage.java:33)
@pazone
Copy link
Owner

pazone commented Jul 6, 2015

Hi. I see that you are using JqueryCoordsProvider(as default). This provider requires jQuery to be included on page. In this case you can use WebDriverCoordsProvider.

new AShot().coordsProvider(new WebDriverCoordsProvider) ...;

@pazone pazone closed this as completed Jul 16, 2015
@shahankit783
Copy link

shahankit783 commented Dec 19, 2016

The above code i.e.
final Screenshot screenshot = new AShot().coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(driver);
will capture only the current visible screen picture in Chrome browser. It will work fine for Firefox browser.

@jenny-jian
Copy link

jenny-jian commented May 9, 2018

I import ashot-1.5.3.jar, when run the test with below keyword, got "ERROR] - unknown error: $ is not defined".
Below is the keyword method:

class ScreenshotHelper {
@Keyword
public void takeWebElementScreenshot(TestObject object) {
WebElement element = WebUiCommonHelper.findWebElement(object, 20)
WebDriver driver = DriverFactory.getWebDriver();
Screenshot screenshot = new AShot().takeScreenshot(driver, element);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants