Author Topic: (Updated)How to invoke element's href in c# webBrowser  (Read 1256 times)

0 Members and 1 Guest are viewing this topic.

Offline liuwei0622

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -5
    • View Profile
(Updated)How to invoke element's href in c# webBrowser
« on: November 13, 2013, 09:09:26 am »


Above is one 'time table' on web page, some items are enable and some are disabled. After I select(mouse left click) one of available time(e.g. 8:30am), then the corresponding 'onClick' event will be invoked. Now I can get the 'webBrowser' object in c#, if I can simulate the selection action via webBrowser?  Below is the code snap shot:
corresponding html code:
Code: [Select]
<div id="timetableZone" style="position: relative; height: 100%;"> <table class="rms_timeSelPick"> <tbody> <tr class="rms_timeSelTitle"> <th class="rms_mon"><div><span class="d">-</span></div></th> <th class="rms_tue"><div><span class="d">-</span></div></th> <th class="rms_wed"><div><span class="d">-</span></div></th> <th class="rms_thu"><div><span class="d">-</span></div></th> <th class="rms_fri"><div><span class="d">-</span></div></th> <th class="rms_sat"><div><span class="d">-</span></div></th> <th class="rms_sun"><div><span class="d">-</span></div></th> </tr> <tr id="rms_timeSel_830" class="rms_timeSel_830"> <td id="rms_mon_830" class="rms_mon"><a href="javascript:;">8:30 am</a></td> <td id="rms_tue_830" class="rms_tue"><a href="javascript:;">8:30 am</a></td> <td id="rms_wed_830" class="rms_wed"><a href="javascript:;">8:30 am</a></td> <td id="rms_thu_830" class="rms_thu"><a href="javascript:;">8:30 am</a></td> <td id="rms_fri_830" class="rms_fri"><a href="javascript:;">8:30 am</a></td> <td id="rms_sat_830" class="rms_sat"><a href="javascript:;">8:30 am</a></td> <td id="rms_sun_830" class="rms_sun"><a href="javascript:;">8:30 am</a></td> </tr> <tr id="rms_timeSel_200" class="rms_timeSel_200"> <td id="rms_mon_200" class="rms_mon"><a href="javascript:;">2:00 pm</a></td> <td id="rms_tue_200" class="rms_tue"><a href="javascript:;">2:00 pm</a></td> <td id="rms_wed_200" class="rms_wed"><a href="javascript:;">2:00 pm</a></td> <td id="rms_thu_200" class="rms_thu"><a href="javascript:;">2:00 pm</a></td> <td id="rms_fri_200" class="rms_fri"><a href="javascript:;">2:00 pm</a></td> <td id="rms_sat_200" class="rms_sat"><a href="javascript:;">2:00 pm</a></td> <td id="rms_sun_200" class="rms_sun"><a href="javascript:;">2:00 pm</a></td> </tr> <tr id="rms_timeSel_245" class="rms_timeSel_245"> <td id="rms_mon_245" class="rms_mon"><a href="javascript:;">2:45 pm</a></td> <td id="rms_tue_245" class="rms_tue"><a href="javascript:;">2:45 pm</a></td> <td id="rms_wed_245" class="rms_wed"><a href="javascript:;">2:45 pm</a></td> <td id="rms_thu_245" class="rms_thu"><a href="javascript:;">2:45 pm</a></td> <td id="rms_fri_245" class="rms_fri"><a href="javascript:;">2:45 pm</a></td> <td id="rms_sat_245" class="rms_sat"><a href="javascript:;">2:45 pm</a></td> <td id="rms_sun_245" class="rms_sun"><a href="javascript:;">2:45 pm</a></td> </tr> <tr id="rms_timeSel_330" class="rms_timeSel_330"> <td id="rms_mon_330" class="rms_mon"><a href="javascript:;">3:30 pm</a></td> <td id="rms_tue_330" class="rms_tue"><a href="javascript:;">3:30 pm</a></td> <td id="rms_wed_330" class="rms_wed"><a href="javascript:;">3:30 pm</a></td> <td id="rms_thu_330" class="rms_thu"><a href="javascript:;">3:30 pm</a></td> <td id="rms_fri_330" class="rms_fri"><a href="javascript:;">3:30 pm</a></td> <td id="rms_sat_330" class="rms_sat"><a href="javascript:;">3:30 pm</a></td> <td id="rms_sun_330" class="rms_sun"><a href="javascript:;">3:30 pm</a></td> </tr> </tbody> </table>
JavaScript on click event code:
[code]
//setup timetable (function(){ var timetable = dojo.query('.rms_timeSelPick')[0]; dojo.query('#timetableZone').attr('aria-live','polite'); //add onclicks to links in tables dojo.query(timetable).query('a').forEach(function(node, index, array){ dojo.connect(node,'onclick',function(e){ if(dojo.hasClass(node,'available')){ dojo.query(timetable).query('.selected').removeClass('selected').attr('aria-checked','false'); dojo.query(node).addClass('selected'); dojo.query(node).attr('aria-checked','true'); var list = dojo.query(timetable).query('.available') for(var time = 0; time < list.length; time++){ var cell = dojo.query(list[time]); if (dojo.hasClass(cell[0], 'selected')) { cell.attr('tabindex', '222'); } else { cell.attr('tabindex', '221'); } } var t = dojo.query(node).attr('value'); dijit.byId('selectedDateTime').attr('value', t[0]); //enable the next button dijit.byId('nextButtonTimeslot').setDisabled(false); } }); });
I noticed there is hyperlink on each item like this:
[font=monospace][size=medium]<td id[/font][/size]="rms_thu_830" class="rms_thu">[font=monospace][size=medium][b]<a [/b][b]href[/b][/font][/size][b]="[/b][b]">[/b][color=#000000][font=monospace][size=medium]8:30 am[/color][/font][/size][font=monospace][size=medium]</a>[/font][/size][font=monospace][size=medium]</td>[/font][/size][color=#000000][font=monospace][size=medium] [/color][/font][/size]
if I can invoke the href in c# webBrowser to trigger the corresponding onClick event in JavaScript?[color=#000000][font=monospace][size=medium] so that I can implement the simulation mouse left click action. Thanks in advance.[/color][/font][/size]
« Last Edit: November 14, 2013, 09:25:35 am by liuwei0622 »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: How to simulate to choose date time in the calendar
« Reply #1 on: November 13, 2013, 05:56:57 pm »
Try looking at HTTP headers and send self-crafted requests to flip the page... if you were on Python, I'd suggest using Mechanize and forget about problems.

Offline ArkPhaze

  • Peasant
  • *
  • Posts: 136
  • Cookies: 20
  • null terminated
    • View Profile
Re: (Updated)How to invoke element's href in c# webBrowser
« Reply #2 on: November 17, 2013, 11:10:11 am »
Screw the webbrowser control and throw it in the trash. What are you using that for? Use WebRequests, and analyze the POST data that is sent via the Javascript that gets executed.
sig=: ArkPhaze

[ J/ASM/.NET/C/C++ - Software Engineer ]