Ghostドライバーを使用してGoogle検索結果ページを解析しようとしています。2番目の検索結果ページを解析する必要があります。そのため、Javaスクリプトを使用して、検索結果ページのソース(html)を調べ、その下のページ番号をクリックして(Ghostドライバーを使用して)ナビゲートしようとしています。次に、次の例外をスローします。
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
driver = new HtmlUnitDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.querySelectorAll('#foot span div table tbody tr td a')[2].click();");
Exception in thread "main" java.lang.UnsupportedOperationException: Javascript is not enabled for this HtmlUnitDriver instance
at org.openqa.selenium.htmlunit.HtmlUnitDriver.getPageToInjectScriptInto(HtmlUnitDriver.java:503)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.executeScript(HtmlUnitDriver.java:458)
at ATest.main(ATest.java:46)