通过使用HTMLUnit按下JS按钮来浏览网站 [英] Navigating through a website by pressing on JS buttons using HTMLUnit
问题描述
我正在尝试使用HTMLUnit 2.36
按下网页上的Javascript按钮,该导航到另一个页面,依此类推... :
I'm attempting to press a Javascript Button on a webpage using HTMLUnit 2.36
which navigates to another page, and so on...:
ScriptResult result = page.executeJavaScript("__doPostBack('LinkBtn_thebutton','')");
Page page = result.getNewPage();
我试图使用上面的代码导致以下错误,原因可能是不再支持getNewPage()
:
I've attempted to use the code above which causes the following error, supposedly because getNewPage()
is no longer supported:
The method GetNewPage() is undefined for type ScriptResult
我也尝试添加getJavaScriptResult()
的演员表,如下所示,但是没有运气:
I've also attempted to add a cast with getJavaScriptResult()
as shown below with no luck:
HtmlPage page1 = (HtmlPage) result.getJavaScriptResult();
引起以下错误:
Exception in thread "main" java.lang.ClassCastException: class net.sourceforge.htmlunit.corejs.javascript.Undefined cannot be cast to class com.gargoylesoftware.htmlunit.html.HtmlPage
推荐答案
不应将result.getJavaScriptResult();
强制转换为空白.如果要重定向页面,请确保启用了重定向:webClient.getOptions().setRedirectEnabled(true);
You are not supposed to cast the result.getJavaScriptResult();
, treat it like a void. If your page is going to be redirected, make sure that redirecting is enabled: webClient.getOptions().setRedirectEnabled(true);
这篇关于通过使用HTMLUnit按下JS按钮来浏览网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!