pazone / ashot

WebDriver Screenshot utility. Take screenshots, crop, prettify, compare
Other
636 stars 157 forks source link

Not able to capture screenshot getting error java.lang.RuntimeException: org.openqa.selenium.JavascriptException: javascript error: $ is not defined #446

Closed ayushkulshrestha closed 7 months ago

ayushkulshrestha commented 8 months ago

Exception in thread "main" java.lang.RuntimeException: org.openqa.selenium.JavascriptException: javascript error: $ is not defined (Session info: chrome=120.0.6099.129) Build info: version: '4.13.0', revision: 'ba948ece5b*' System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.5.1', java.version: '17.0.4' Driver info: org.openqa.selenium.chrome.ChromeDriver Command: [c400ab1b2c4a4f109f43871f8ae231ea, executeScript {script=function Coords(el) { this.left = parseInt(el.offset().left); this.top = parseInt(el.offset().top); this.right = parseInt(this.left + el.outerWidth()); this.bottom = parseInt(this.top + el.outerHeight()); }

Coords.prototype.toString = function () { var x = Math.max(this.left, 0); var y = Math.max(this.top, 0); return JSON.stringify({ x:x, y:y, width:this.right - x, height:this.bottom - y }); };

return [(new Coords($(arguments[0]))).toString()]; , args=[{element-6066-11e4-a52e-4f735466cecf=5D73C4A7843036A1A1C0136D3EA39B39_element_110}]}] Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 120.0.6099.129, chrome: {chromedriverVersion: 120.0.6099.109 (3419140ab66..., userDataDir: /var/folders/k3/c1gz8zmx6rv...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:51427}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: mac, proxy: Proxy(), se:cdp: ws://localhost:51427/devtoo..., se:cdpVersion: 120.0.6099.129, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true} Session ID: c400ab1b2c4a4f109f43871f8ae231ea at ru.yandex.qatools.ashot.util.InnerScript.execute(InnerScript.java:32) at ru.yandex.qatools.ashot.util.JsCoords.findCoordsWithJquery(JsCoords.java:24) at ru.yandex.qatools.ashot.coordinates.JqueryCoordsProvider.ofElement(JqueryCoordsProvider.java:14) at ru.yandex.qatools.ashot.coordinates.CoordsProvider.ofElements(CoordsProvider.java:21) at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:116) at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:134) at aprendizado.selenyum.imageComparison.main(imageComparison.java:52) Caused by: org.openqa.selenium.JavascriptException: javascript error: $ is not defined (Session info: chrome=120.0.6099.129) Build info: version: '4.13.0', revision: 'ba948ece5b*' System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.5.1', java.version: '17.0.4' Driver info: org.openqa.selenium.chrome.ChromeDriver Command: [c400ab1b2c4a4f109f43871f8ae231ea, executeScript {script=function Coords(el) { this.left = parseInt(el.offset().left); this.top = parseInt(el.offset().top); this.right = parseInt(this.left + el.outerWidth()); this.bottom = parseInt(this.top + el.outerHeight()); }

Coords.prototype.toString = function () { var x = Math.max(this.left, 0); var y = Math.max(this.top, 0); return JSON.stringify({ x:x, y:y, width:this.right - x, height:this.bottom - y }); };

return [(new Coords($(arguments[0]))).toString()]; , args=[{element-6066-11e4-a52e-4f735466cecf=5D73C4A7843036A1A1C0136D3EA39B39_element_110}]}] Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 120.0.6099.129, chrome: {chromedriverVersion: 120.0.6099.109 (3419140ab66..., userDataDir: /var/folders/k3/c1gz8zmx6rv...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:51427}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: mac, proxy: Proxy(), se:cdp: ws://localhost:51427/devtoo..., se:cdpVersion: 120.0.6099.129, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true} Session ID: c400ab1b2c4a4f109f43871f8ae231ea at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200) at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133) at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:52) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:191) at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:196) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:171) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602) at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:467) at ru.yandex.qatools.ashot.util.InnerScript.execute(InnerScript.java:30) ... 6 more

How to resolve this ?

valfirst commented 7 months ago

@ayushkulshrestha please use WebDriverCoordsProvider instead of JqueryCoordsProvider

valfirst commented 7 months ago

Duplicate of #188