我正在尝试点击此网站上的搜索按钮:
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("ctl00$ctl00$ctl00$cph1$cph1$QuickSearchAll1$QuickFlightSearchControl1$ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch_LinkButton", "", true, "", "", 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>
Run Code Online (Sandbox Code Playgroud)
该按钮是站点左侧的搜索按钮.我使用HtmlUnitScripter附加组件为firefox生成一个类,但即使它生成了将填充表单的代码,它也不会生成将单击按钮的代码.
按下按钮后,会出现一个加载屏幕,然后显示结果.通常,下一个代码应该将结果页面返回到page变量中
HtmlElement theElement5 = (HtmlElement) page.getElementById("ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch");
page = (HtmlPage) theElement5.click();
Run Code Online (Sandbox Code Playgroud)
但它只返回填写表单的上一页.有没有一种特殊的方法来处理这个按钮,或者我找不到合适的按钮来点击?任何帮助将不胜感激.
编辑:
我使用时得到的例外
ScriptResult result = page.executeJavaScript("document.getElementById('ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch_Table').onclick()");
final Page newPage = result.getNewPage();
Run Code Online (Sandbox Code Playgroud)
在下面
Exception in thread "main" ======= EXCEPTION START ========
EcmaError: lineNumber=[64] …Run Code Online (Sandbox Code Playgroud) 我是HtmlUnit的新手,我甚至不确定它是否适合我的项目.我正在尝试解析一个网站并从中提取我需要的值.我需要从这里获得值"07:05",
<span class="tim tim-dep">07:05</span>
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用getTextContent()来提取值,但我不知道如何选择特定的跨度.我使用getElementById来查找
<div>
Run Code Online (Sandbox Code Playgroud)
这个表达式所属的标签,但当我得到该div的文本内容时,我得到了一整行含有大量不必要数据的文本.有人可以告诉我如何选择这个表达式,可能使用类名吗?
我正在尝试获取所选项目的文本并在Toast消息中显示它.这是我写的代码:
final ListView lv = (ListView)findViewById(R.id.firstflightlist);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
TextView c = (TextView) arg0.findViewById(arg1.getId());
String text = c.getText().toString();
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
}});
Run Code Online (Sandbox Code Playgroud)
列表视图是单选列表视图.当我单击列表中的任何项目时,它始终显示列表的第一项.可能是什么导致了这个?如何获取所选项目的文本?