0
我想用Ghost驅動程序解析Google搜索結果頁面,爲此我需要解析第二個搜索結果頁面。因此,使用Java腳本,我試圖通過搜索結果頁面的源代碼(html)並通過單擊(使用Ghost驅動程序)下方的頁碼進行導航。然後它拋出下面的異常。嵌入JavaScript解析並點擊硒鬼驅動程序中的網頁
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)