8

この Web サイトの検索ボタンをクリックしようとしています。

http://www.amadeusepower.com/trek/portals/trek/default.aspx?Culture=en-US

ボタンはここのどこかにある

<table cellpadding="0" cellspacing="0" class="QuickSearchFormFlightModuleButtonsTable"
                width="100%">
                <tr>
                    <td class="cell1">
                        <a id="ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_hlFlightDetailedSearch" href="javascript:if(typeof notRedirectToTop == 'undefined'){document.forms[0].target = '_top';}__doPostBack('ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_hlFlightDetailedSearch', '');">Advanced options</a>
                    </td>
                    <td class="cell2">
                    </td>
                    <td class="cell3">

                    </td>
                    <td class="cell4">
                    </td>
                    <td class="cell5">
                        <script>DumpButtonHTML('ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch','QuickSearchModuleFlightSearchStartSearchButton','QuickSearchModuleFlightSearchStartSearch','javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl00$ctl00$cph1$cph1$QuickSearchAll1$QuickFlightSearchControl1$ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch_LinkButton&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, true, true));LockButton(this,\'\',true);Loading(IsValidForTableButton(\'\',true),\'DefaultSplash_SplashScreen\',\'/trek/App_Themes/trek_theme1/Templates/SplashScreens/\',\'ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtSearch_txtFrom;ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtSearch_txtTo;ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtDepartureDate_txtDate;ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtReturnDate_txtDate\');','True','Search','100px','True','','trek_theme1');</script>
                    </td>
                </tr>
            </table>

ボタンはサイト左側の検索ボタンです。クラスを生成するためにFirefox用のHtmlUnitScripterアドオンを使用しましたが、フォームに入力するコードを生成しても、ボタンをクリックするコードを生成しません。

ボタンを押すと、ロード画面が表示され、結果が表示されます。通常、この次のコードは結果ページをpage変数に返す必要があります

HtmlElement theElement5 = (HtmlElement) page.getElementById("ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch");
page = (HtmlPage) theElement5.click();

ただし、フォームが入力された前のページのみが返されます。このボタンを処理する特別な方法はありますか、それともクリックする正しいボタンが見つかりませんか? どんな助けでも大歓迎です。

編集:

使用したときに発生する例外

ScriptResult result = page.executeJavaScript("document.getElementById('ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch_Table').onclick()");
final Page newPage = result.getNewPage();

以下です

Exception in thread "main" ======= EXCEPTION START ========
EcmaError: lineNumber=[64] column=[0] lineSource=[<no source>] name=[TypeError] sourceName=[http://www.amadeusepower.com/trek/Amadeus/js/Functions.js] message=[TypeError: Cannot read property "cancelBubble" from undefined (http://www.amadeusepower.com/trek/Amadeus/js/Functions.js#64)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "cancelBubble" from undefined (http://www.amadeusepower.com/trek/Amadeus/js/Functions.js#64)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:601)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:555)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:530)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:979)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScript(HtmlPage.java:947)
at htmlunittest.test.com.TestEkoBilet.main(TestEkoBilet.java:51)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "cancelBubble" from undefined (http://www.amadeusepower.com/trek/Amadeus/js/Functions.js#64)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3624)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3634)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectPropNoWarn(ScriptRuntime.java:1488)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1233)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:81)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1531)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:275)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:546)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:654)
... 7 more
Enclosed exception: 
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "cancelBubble" from undefined (http://www.amadeusepower.com/trek/Amadeus/js/Functions.js#64)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3624)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3634)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectPropNoWarn(ScriptRuntime.java:1488)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1233)
at script.StopEvent(http://www.amadeusepower.com/trek/Amadeus/js/Functions.js:64)
at script.onclick(onclick event for HtmlTable[<table id="ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch_Table" onmouseout="this.className='QuickSearchModuleFlightSearchStartSearchButton';" border="0" width="100px" class="QuickSearchModuleFlightSearchStartSearchButton" cellpadding="0" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl00$ctl00$cph1$cph1$QuickSearchAll1$QuickFlightSearchControl1$ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch_LinkButton&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, true, true));LockButton(this,'',true);Loading(IsValidForTableButton('',true),'DefaultSplash_SplashScreen','/trek/App_Themes/trek_theme1/Templates/SplashScreens/','ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtSearch_txtFrom;ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtSearch_txtTo;ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtDepartureDate_txtDate;ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtReturnDate_txtDate');StopEvent(event);" onmouseover="this.className='QuickSearchModuleFlightSearchStartSearchButtonOver';" style="cursor:pointer;cursor:hand;" cellspacing="0">] in http://www.amadeusepower.com/trek/portals/trek/default.aspx?Culture=en-US)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:81)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1531)
at script(injected script:1)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:275)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:546)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:654)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:601)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:555)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:530)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:979)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScript(HtmlPage.java:947)
at htmlunittest.test.com.TestEkoBilet.main(TestEkoBilet.java:51)
======= EXCEPTION END ========

サイト内の他のスクリプトにアクセスしようとしていると思いますが、現在のページにはありません。htmlunit は何らかの関数を介してこれらのスクリプトにアクセスできますか?

編集2:

ページの冒頭付近に次のスクリプトを見つけました。検索ボタンと関係ありますか?ボタンのIDがあるようですが、よくわかりません。

</script>
<form name="aspnetForm" method="post" action="default.aspx?Culture=en-US" onsubmit="javascript:return WebForm_OnSubmit();" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch')" id="aspnetForm">
  <div>
    <input type="hidden" name="__WPPS" id="__WPPS" value="s"/>
    <input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value=""/>
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value=""/>
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value=""/>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPaA8FDzhkMDIyYzJhNTQzOGU2NBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WBAVXY3RsMDAkY3RsMDAkY3RsMDAkY3BoMSRjcGgxJFF1aWNrU2VhcmNoQWxsMSRRdWlja0ZsaWdodFNlYXJjaENvbnRyb2wxJGNoa0NhbGVuZGFyU2VhcmNoBUxjdGwwMCRjdGwwMCRjdGwwMCRjcGgxJGNwaDEkUXVpY2tTZWFyY2hBbGwxJFF1aWNrRmxpZ2h0U2VhcmNoQ29udHJvbDEkY2hrRmlmBVJjdGwwMCRjdGwwMCRjdGwwMCRjcGgxJGNwaDEkUXVpY2tTZWFyY2hBbGwxJFF1aWNrRmxpZ2h0U2VhcmNoQ29udHJvbDEkY2hrQWRkZmFtaWx5BVFjdGwwMCRjdGwwMCRjdGwwMCRjcGgxJGNwaDEkUXVpY2tTZWFyY2hBbGwxJFF1aWNrRmxpZ2h0U2VhcmNoQ29udHJvbDEkY2hrRm9yY2VQVEMp3jYJ9QEgzYItUgLEnRZgeEkhsA=="/>
  </div>
  <script type="text/javascript">
4

2 に答える 2

2

クリック機能はテーブル要素にあります。これを試してください(自分では試していません):

HtmlElement theElement5 = (HtmlElement) page.getElementById("ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch_Table");
page = (HtmlPage) theElement5.click();

これが機能しない場合は、ログ オン デバッグ レベルを有効にして何が起こっているかを確認するか、これを試してください (FF で動作します):

ScriptResult result = page.executeJavaScript("document.getElementById('ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch_Table').onclick()");
final Page newPage = result.getNewPage();

ヒント: Firebug を使用してページ変数と要素をチェックし、page.asXml() を使用してページの実際の状態を取得します。

于 2013-05-18T17:17:38.530 に答える