任何想法如何點擊這個「形象」與HtmlUnit
?點擊的HtmlUnit HREF「圖像」
<a href="play.php?choose=2">
<div id="champbox" style="background-image: url(http:xxx.jpg);float:right;"></div></a>
試過用的HtmlAnchor和XPath點擊它,但得到象這樣的錯誤:
java.lang.NullPointerException
或
com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[a] attributeName=[href] attributeValue=[play.php?choose=2]
這裏是各地重現該問題:
你鴕鳥政策需要一個帳戶。
我的代碼:
//Webclient Options
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getCookieManager().setCookiesEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
// Cut out the Login (better Overview)
HtmlAnchor anchor = page2.getAnchorByHref("play.php");
HtmlPage page3 = anchor.click();
System.out.println(page3.getTitleText());
System.out.println(page3.getUrl());
//To-Do: Click left or right Picture
/*
HtmlAnchor a1 = page3.getAnchorByHref("play.php?choose=2");
System.out.println(a1.asXml());
HtmlAnchor a2 = page3.getFirstByXPath("//a[@href='play.php?choose=2']");
System.out.println(a2.asXml());
a1.click();
a2.click();
*/
/*
ScriptResult result = page3.executeJavaScript("vapi-client.js:41");
result.getJavaScriptResult();
System.out.println("result: "+ result);
*/
更新:並獲得了新的問題有:
檢查之前訪問你的瀏覽器..
揣摩了這一點;)
不是在談論這一點。用HtmlUnit搜索點擊這個「圖像」的方法。像image.click();但是,謝謝;) – BiFi
對不起,我不是那麼好:( –