Author Topic: How can i use mouse event in webBrowser1_DocumentCompleted()  (Read 1354 times)

0 Members and 1 Guest are viewing this topic.

Offline liuwei0622

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -5
    • View Profile
How can i use mouse event in webBrowser1_DocumentCompleted()
« on: November 04, 2013, 09:44:44 am »
I am trying to develop one tool which can auto log on to the site:
https://www.myrta.com/wps/portal/extvp/myrta/licence/tbs/tbs-change/
After I entered valid 'Booking number' and 'Family name', the state of 'Continue' button will switch to 'enabled', then once I click the 'Continue', it will go to next page.
here is my code:
Code: [Select]
private void btnSet_Click()
         {
            int X = 300;
            int Y = 757;
             SetCursorPos(X, Y);
             Thread.Sleep(5000);
             mouse_event((int)(MouseEventFlags.LeftDown | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero);
             mouse_event((int)(MouseEventFlags.LeftUp | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero);
             Thread.Sleep(5000);
         }

My question is i have found the mouse cursor postion just like X = 300 & Y = 757.  i call btnSet_Click() in webBrowser1_DocumentCompleted() like below:
 
Code: [Select]
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
         {
            string pathAndQuery = e.Url.PathAndQuery;
             if (pathAndQuery.IndexOf("myTests/SelectionHandle.do") != -1)
             {
                 // fill the Account information in current web
                 this.fillTestAccount();
                  Thread.Sleep(1000);
                  this.btnSet_Click();
             }
        }

The mouse cursor have move to the appointed position(button).but the click event  is not useful for the button.. I have test the mouse event code  in another test program  . It's fine. I do not know the reason for this issue.

Here is my question:
In my tool, I can simulate to fill in the values of 'Booking number' and 'Family name' automatically, but how can I simulate to click 'continue' button? The 'Continue' button was placed in the website page, I can get the pixel location of the 'Continue' button, I know it's position exactly, I want to simulate the 'mouse left click event' to click the button,  but it does not work against this website.
I tried 'mouse left click event' function in my code against another website, it works fine.  But when I invoked the code in the method  webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e), it does not work.
 
Could you please kindly give me a sample to how to implement the 'mouse left click' function, so that the button in the website page can be triggered? Thanks in advance. In addition, I have to explain why did I choose the mouse operate to auto login instead of the other way, although below code is simpler and easier,
I have tested the www.bing.com web page using below code:
 
Code: [Select]
private void button1_Click(object sender, EventArgs e)
 {
 this.webBrowser1.Navigate("www.bing.com");
 }
 
 private void button2_Click(object sender, EventArgs e)
 {
 this.webBrowser1.Document.GetElementById("dhp").InvokeMember("onclick");
 }



When I click button1, it will navigate to the page and when I click the button2, it will run the script successfully.
But in my case, I can get the id attribute of the 'continue' button, but can not get the "click" or "onclick" operation in script. See detail info in below:
 
Code: [Select]
<!-- button -->
 <div class="rms_buttonRowStandard rms_btnSmall">
 <button dojoType="dijit.form.Button" type="submit" id="submitNoLogin"
 class="rms_initDisable rms_submit rms_btnSmall" tabindex="225">
 Continue
 </button>
 <>

 So I have to choose the mouse operate to simulate auto login. Any suggestion is appreciate. Thanks again.   ;)
« Last Edit: November 04, 2013, 08:01:55 pm by ande »

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: How can i use mouse event in webBrowser1_DocumentCompleted()
« Reply #1 on: November 04, 2013, 08:08:58 pm »
I took the liberty of formatting your post a bit... I suggest you use the code tags in the future.

Anyway, without reading your post in great details I think you can just simulate a real click, not try to call the onclick event. Something like this:
Code: [Select]
webbrowser1.Document.GetElementyId("button_name").InvokeMember("click");

If this does not work you could always try to submit the forum, something like:
Code: [Select]
webBrowser1.Document.GetElementById("FormID").InvokeMember("submit");

If this does not work, you could always inject javascript into the document and do it from there.


Sorry if this reply does not make sense or is not of help, I was in a bit of a hurry when I replied.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline liuwei0622

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -5
    • View Profile
Re: How can i use mouse event in webBrowser1_DocumentCompleted()
« Reply #2 on: November 05, 2013, 06:23:02 am »
Excellent !! It work fine when i use the form id to submit . Thank you  ;D

Offline liuwei0622

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -5
    • View Profile
Re: How can i use mouse event in webBrowser1_DocumentCompleted()
« Reply #3 on: November 05, 2013, 03:39:04 pm »
I met another problem,  any help is appreciate .

How can I get the var of Java Script from c# webBrowser? 
Below is part code of the html, the function in JS does not have name.

<script type="text/javascript">
dojo.require("myrta_tbs_dojo.portlethelper.chooseTime");
var portletHelper_ns_Z7_0HEPVU271835D0IFC7B1OP10Q2_;
var containsPreferredDate = false;
var containsSelectedDate = true;
var weekDate = new Date('Mon Nov 25 00:00:00 EST 2013');
var timeslots = { "ajaxresult" : { "slots" : {
  "nextAvailableDate" : "27/11/2013 14:50",
  "listTimeSlot" : [ {
    "startTime" : "25/11/2013 8:35",
    "availability" : false,
    "slotNumber" : null 
  }, {
    "startTime" : "01/12/2013 15:35",
    "availability" : false,
    "slotNumber" : null
  } ]
}}};
var stSelectedSlot = '2013/11/28 08:35';
var timetableInterval = [515, 890, 935];
var extendedRangeFlag = false;
 
dojo.addOnLoad( function() {
  portletHelper_ns_Z7_0HEPVU271835D0IFC7B1OP10Q2_ =
      new myrta_tbs_dojo.portlethelper.chooseTime({portlet: portlet_ns_Z7_0HEPVU271835D0IFC7B1OP10Q2_});
 
    dojo.require("myrta_tbs_dojo.portlethelper.chooseLocation");

how can I get the value of timeslots in c# code via WebBrowser? thanks.
« Last Edit: November 05, 2013, 03:47:00 pm by liuwei0622 »

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: How can i use mouse event in webBrowser1_DocumentCompleted()
« Reply #4 on: November 06, 2013, 12:18:32 am »
I met another problem,  any help is appreciate .

How can I get the var of Java Script from c# webBrowser? 
Below is part code of the html, the function in JS does not have name.

<script type="text/javascript">
dojo.require("myrta_tbs_dojo.portlethelper.chooseTime");
var portletHelper_ns_Z7_0HEPVU271835D0IFC7B1OP10Q2_;
var containsPreferredDate = false;
var containsSelectedDate = true;
var weekDate = new Date('Mon Nov 25 00:00:00 EST 2013');
var timeslots = { "ajaxresult" : { "slots" : {
  "nextAvailableDate" : "27/11/2013 14:50",
  "listTimeSlot" : [ {
    "startTime" : "25/11/2013 8:35",
    "availability" : false,
    "slotNumber" : null 
  }, {
    "startTime" : "01/12/2013 15:35",
    "availability" : false,
    "slotNumber" : null
  } ]
}}};
var stSelectedSlot = '2013/11/28 08:35';
var timetableInterval = [515, 890, 935];
var extendedRangeFlag = false;
 
dojo.addOnLoad( function() {
  portletHelper_ns_Z7_0HEPVU271835D0IFC7B1OP10Q2_ =
      new myrta_tbs_dojo.portlethelper.chooseTime({portlet: portlet_ns_Z7_0HEPVU271835D0IFC7B1OP10Q2_});
 
    dojo.require("myrta_tbs_dojo.portlethelper.chooseLocation");

how can I get the value of timeslots in c# code via WebBrowser? thanks.

I would go regex. However, timeslots is a collection of information, but you could grab it all with something like this: /var\stimeslots\s=\s\{(.*)\}\}\}\;/
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true