seleniumで、巨大なページの画面キャプチャを取得するとOutOfMemoryが発生してしまいます。
短時間で大量のJavaヒープを消費するためOutOfMemoryErrorになっているようなので、
巨大なページであればキャプチャを取らないように条件分岐させたいと思っています。
** そこで表示したページのサイズ(画面キャプチャのサイズ、もしくは類似のサイズ)をselenumの何かしらのクラスで取得する方法**
をご存知な方いらっしゃいましたらお教え頂きたいです。
▼具体的な問題▼
具体的には、
http://backyard.imjp.co.jp/static/feed/atom.xml
を以下のコードで画面キャプチャを採取しようとするとOutOfMemoryが発生します。
▼キャプチャ採取のコード▼
//取得したURLのスクリーンショット作成 File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File(scrFileName));
▼発生している例外▼
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.lang.StringCoding.decode(StringCoding.java:215) at java.lang.String.<init>(String.java:451) at java.lang.String.<init>(String.java:503) at org.openqa.selenium.remote.http.HttpMessage.getContentString(HttpMessage.java:110) at org.openqa.selenium.remote.http.HttpResponse.getContentString(HttpResponse.java:1) at org.openqa.selenium.remote.http.JsonHttpResponseCodec.decode(JsonHttpResponseCodec.java:76) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:137) at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:170) at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:393) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:568) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:618) at org.openqa.selenium.firefox.FirefoxDriver.getScreenshotAs(FirefoxDriver.java:354) at sample.SandBox.main(SandBox.java:168)
▼試してみたけどダメだったこと▼
0. JVMの起動パラメータで、-Xms1024m、-Xmx1024mにした。
0. ファイルコピーをせずに一時ディレクトリでのキャプチャ採取のみにした。(FileUtils.copyFile(scrFile, new File(scrFileName)); をコメントアウト)
▼やりたいこと。質問▼
短時間で大量のJavaヒープを消費するためOutOfMemoryErrorになっているようなので、
巨大なページの画面キャプチャ採取をあきらめ、
巨大なページであればキャプチャを取らないように条件分岐させたいと思っています。
** そこで表示したページのサイズ(画面キャプチャのサイズ、もしくは類似のサイズ)をselenumの何かしらのクラスで取得する方法**
をご存知の方はお教え頂きたいです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。