我正在创建一个工具,其中我使用了C#浏览器控件,它自动登录IRCTC并预订票证。一切都很好,除了一页。我无法点击浏览器,如何找到锚点并点击C#browser.Below是HTML:
<table class="rf-dt width100" id="avlAndFareForm:trainbtwnstns">
<colgroup span="16">
</colgroup>
<thead class="rf-dt-thd" id="avlAndFareForm:trainbtwnstns:th">
<tr class="rf-dt-shdr" id="avlAndFareForm:trainbtwnstns:ch">
<th id="avlAndFareForm:trainbtwnstns:j_idt261" scope="col" class="rf-dt-shdr-c">
Train No.
<div id="up" style="float: right; display: none;">
</div>
<div id="down" style="float: right; display: none;">
</div>
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt265" scope="col" class="rf-dt-shdr-c">
Train Name
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt268" scope="col" class="rf-dt-shdr-c">
From
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt271" scope="col" class="rf-dt-shdr-c">
Departure
<div id="up" style="float: right; display: block;" class="up-hdr">
</div>
<div id="down" style="float: right; display: none;">
</div>
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt275" scope="col" class="rf-dt-shdr-c">
To
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt278" scope="col" class="rf-dt-shdr-c">
Arrival
<div id="up" style="float: right; display: none;">
</div>
<div id="down" style="float: right; display: none;">
</div>
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt282" scope="col" class="rf-dt-shdr-c">
Dist.(Km)
<div id="up" style="float: right; display: none;">
</div>
<div id="down" style="float: right; display: none;">
</div>
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt286" scope="col" class="rf-dt-shdr-c">
Travel Time
<div id="up" style="float: right; display: none;">
</div>
<div id="down" style="float: right; display: none;">
</div>
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt290" scope="col" class="rf-dt-shdr-c">
M
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt293" scope="col" class="rf-dt-shdr-c">
T
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt296" scope="col" class="rf-dt-shdr-c">
W
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt299" scope="col" class="rf-dt-shdr-c">
T
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt302" scope="col" class="rf-dt-shdr-c">
F
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt305" scope="col" class="rf-dt-shdr-c">
S
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt308" scope="col" class="rf-dt-shdr-c">
S
</th>
<th id="avlAndFareForm:trainbtwnstns:j_idt311" scope="col" class="rf-dt-shdr-c">
Class
</th>
</tr>
</thead>
<tbody class="rf-dt-b" id="avlAndFareForm:trainbtwnstns:tb">
<tr class="rf-dt-r" id="avlAndFareForm:trainbtwnstns:9">
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:9:j_idt261">
<a onclick="trainScheFunc('12141','CSTM','Thu Jul 03 00:00:00 IST 2014')" href="#">12141</a>
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt265">
RAJENDRA NGR EXP
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt268">
CSTM
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt271">
23:25
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt275">
JBP
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt278">
14:15
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt282">
997
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt286">
14:50
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt290">
Y
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt293">
Y
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt296">
Y
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt299">
Y
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt302">
Y
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt305">
Y
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt308">
Y
</td>
<td class="rf-dt-c" id="avlAndFareForm:trainbtwnstns:6:j_idt311">
<a onclick="availFareEnq(this,'12141','Thu Jul 03 00:00:00 IST 2014','1A','CSTM','JBP',true)">
1A</a> <a onclick="availFareEnq(this,'12141','Thu Jul 03 00:00:00 IST 2014','2A','CSTM','JBP',true)">
2A</a> <a onclick="availFareEnq(this,'12141','Thu Jul 03 00:00:00 IST 2014','3A','CSTM','JBP',true)">
3A</a> <a onclick="availFareEnq(this,'12141','Thu Jul 03 00:00:00 IST 2014','SL','CSTM','JBP',true)">
SL</a> <span id="ttf" style="display: none;">O,</span>
</td>
</tr>
</tbody>
<tbody id="avlAndFareForm:trainbtwnstns:sc">
<tr>
<td style="display: none">
<script type="text/javascript"> new RichFaces.ui.DataTable("avlAndFareForm:trainbtwnstns", { "ajaxEventOptions": {} })</script>
</td>
</tr>
</tbody>
</table>
在这里,我想通过浏览器点击下面。我无法找到下面的锚点:请帮帮我:
<a onclick="availFareEnq(this,'12141','Thu Jul 03 00:00:00 IST `2014','SL','CSTM','JBP',true)"> SL</a>.
答案 0 :(得分:0)
您可以将html注入浏览器控件中加载的页面并加载jquery,然后以与使用jquery查找锚标记并单击它相同的方式注入javascript。
HtmlElement head = idOfBrowserControl.Document.GetElementsByTagName("head")[0];
HtmlElement script1 = idOfBrowserControl.Document.CreateElement("script");
script.SetAttribute("type", "text/javascript");
script.SetAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js");
HtmlElement script2 = idOfBrowserControl.Document.CreateElement("script");
script.SetAttribute("type", "text/javascript");
script.InnerHtml = "function clickAnchor() { $($('a', '#avlAndFareForm:trainbtwnstns:6:j_idt311')[0]).click();}}";
head.AppendChild(script1);
head.AppendChild(script2);
然后,当您想要点击它时,请执行
idOfBrowserControl.Document.InvokeScript("clickAnchor");
你不必注入jQuery,我只是这样做因为我使用jQuery来做所有事情......这样更容易。