Javascript 尝试截图时出现WebDriverException
因此,我试图从firefox浏览器中截取一个屏幕截图,我得到以下例外:Javascript 尝试截图时出现WebDriverException,javascript,java,selenium-webdriver,selenium-firefoxdriver,Javascript,Java,Selenium Webdriver,Selenium Firefoxdriver,因此,我试图从firefox浏览器中截取一个屏幕截图,我得到以下例外: org.openqa.selenium.WebDriverException: [Exception... "Data conversion failed because significant data would be lost" nsresult: "0x80460003 (NS_ERROR_LOSS_OF_SIGNIFICANT_DATA)" location: "JS frame :: resource://g
org.openqa.selenium.WebDriverException: [Exception... "Data conversion failed because significant data would be lost" nsresult: "0x80460003 (NS_ERROR_LOSS_OF_SIGNIFICANT_DATA)" location: "JS frame :: resource://gre/modules/AsyncShutdown.jsm :: observe :: line 551" data: no]
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'fd9ab02a8254', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-862.el7.x86_64', java.version: '1.8.0_232'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 72.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20200107212822, moz:geckodriverVersion: 0.26.0, moz:headless: true, moz:processID: 577, moz:profile: /tmp/rust_mozprofile3kZelv, moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, platformVersion: 3.10.0-862.el7.x86_64, rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 7e2460a8-267c-4e91-9774-ad3fb5e4e808
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)
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.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:343)
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)
....
抛出它的java代码行:
File srcFile=((TakesScreenshot)驱动程序).getScreenshotAs(OutputType.File)代码>
该代码在多台机器上运行良好,但在尝试在新机器上安装后,我遇到此错误
有人知道是什么引起的吗?我从一个容器运行应用程序经过多次尝试,没有什么东西可以帮助解决这个问题:
- 检查您尝试截图的元素的可见性。我试着拍一张桌子的照片,但是里面有一些看不见的元素,这让程序崩溃了
if(element.isDisplayed())
- 停止元素并创建一个拼图:一行一行地绘制并使用
BufferedImage bi=new BufferedImage(element.getSize().width,element.getSize().height,BufferedImage.TYPE_INT_RGB)代码>
- 等待使用以下命令加载元素:
WebDriverWait wait=newwebdriverwait(驱动程序,300);
wait.until(预期条件。元素的可视性)(By.id(“报告表”));
wait.until(webDriver->((JavascriptExecutor)webDriver).executeScript(“return document.readyState”).equals(“complete”)代码>