当我使用Ashot和selenium来捕获特定webelement的屏幕截图时,它不起作用。我还附上了日志以供参考。
截图获取整个页面正在运行。
注意:我已经更新了最新的jar的评论中提到
Iam使用Chrome驱动程序、selenium 3.8.1独立jar、Ashot 1.5.2 jar。
@Test
public void launchBrowser()
{
System.setProperty("webdriver.chrome.driver","/Applications/webdriver/chromedriver");
driver = new ChromeDriver();
}
@Test
public void openApplication() throws IOException, InterruptedException
{
driver.get("https://myurl");
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 50);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("commonuileftpanel")));
WebElement portal =driver.findElement(By.id("commonuileftpanel"));
Screenshot myScreenshot = new AShot().takeScreenshot(driver,portal);
BufferedImage original = myScreenshot.getImage();
BufferedImage expected = ImageIO.read(new File("/Applications/webdriver/results.png"));
ImageDiff diff = new ImageDiffer().makeDiff(original, expected);
BufferedImage difffullImage = diff.getMarkedImage();
File outputfile = new File("/Applications/webdriver/diffImage.png");
ImageIO.write(difffullImage, "PNG", outputfile);
Boolean diffval = diff.hasDiff();
Assert.assertFalse(diffval);
driver.quit();
}
@Test
public void closeDriver()
{
if(driver!=null)
{
driver.close();
}
错误消息:
Starting ChromeDriver 2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e) on port 3753
Only local connections are allowed.
Jan 12, 2018 4:02:52 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
ChromeDriver: chrome on MAC (d1a7d84c06ae31e76c872e6be1a61824)
PASSED: closeDriver
PASSED: launchBrowser
FAILED: openApplication
org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'offset' of null
(Session info: chrome=63.0.3239.132)
(Driver info: chromedriver=2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform=Mac OS X 10.13.1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'test', ip: '', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.1', java.version: '1.8.0_152'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.34.522932 (4140ab217e1ca1..., userDataDir: /var/folders/j_/f03djz4n2bv...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 63.0.3239.132, webStorageEnabled: true}
Session ID: d1a7d84c06ae31e76c872e6be1a61824
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:537)
at ru.yandex.qatools.ashot.util.JsCoords.findCoordsWithJquery(JsCoords.java:30)
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:115)
at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:132)
at ExampleSel3.screenshotParticularTag(ExampleSel3.java:187)
at ExampleSel3.openApplication(ExampleSel3.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:571)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.runSuites(TestNG.java:1028)
at org.testng.TestNG.run(TestNG.java:996)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
错误说明了一切:
org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'offset' of null
看起来您的执行直到new AShot()。截图(驱动程序、门户);
您的主要问题是正在使用的二进制文件之间的版本兼容性,如下所示:
有关错误sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
的详细讨论,您可以查看此讨论
我目前正在尝试实现Ashot来为我当前的项目截图,它正在为桌面工作。 但我想知道如何在iOS和Android设备上实现它,互联网上没有太多信息。 我使用了以下视口,它正在为iPad截图: 屏幕截图FullPage=new AShot()。拍摄策略(ShootingStrategies.viewportRetina(100,0,0,2))。截图(司机); 但是我想知道如何使用给定的属性来为其他IOS
我试图在一个网页中给出的表格的屏幕截图。和我在代码中提供的相同元素xpath,但是Ashot代码正在捕获其他位置的屏幕截图。 我也尝试过其他截图代码, 但它给了我错误,我可以通过阅读这个链接来修复:https://github.com/pazone/ashot/issues/93,然后我使用下面的代码: 请帮助,因为此代码正在给我网页某些随机部分的屏幕截图。我也试图捕获其他元素,但我再次没有得到正
在selenium web驱动程序中,我无法使用testng和maven将其显示在控制台中 JAVAlang.VerifyError:(类:junereleasemain/NewTest,方法:testFirstResult签名:()V)java函数的参数不兼容。朗,同学们。java上的getDeclaredMethods0(本机方法)。朗,同学们。java上的privateGetDeclared
我需要使用Sikuli的自动化,但我无法采取截图。问题是,当我点击“截屏”或“创建区域”时,IDE会被隐藏,但选择区域选项不会出现....
问题内容: 我想获得活动的“全页”屏幕截图。该视图包含一个RecyclerView,其中包含许多项。 我可以使用此功能拍摄当前视图的屏幕截图: 但是它仅包含我可以正常查看的项目(符合预期)。 截屏时,有什么方法可以使RecyclerView神奇地完整显示(一次显示所有项目)? 如果没有,我应该如何解决这个问题? 问题答案: 这是我的解决方案,当 所有项目的尺寸都相同 并且 只有一种类型的项目时 。
问题内容: 我正在构建一个称为“ HTML测验”的东西。它完全在JavaScript上运行,非常酷。 最后,弹出一个结果框,显示“您的结果:”,它显示了他们花费了多少时间,他们得到了多少百分比以及他们从10个问题中得出了多少个问题。我想有一个按钮,上面写着“捕获结果”,并使其以某种方式截取屏幕截图或div,然后仅在页面上显示捕获的图像即可在其中单击鼠标右键并“将图像另存为”。 我真的很想这样做,以