EvilZone
Programming and Scripting => Projects and Discussion => : liuwei0622 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:
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:
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:
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:
<!-- 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. ;)
-
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:
webbrowser1.Document.GetElementyId("button_name").InvokeMember("click");
If this does not work you could always try to submit the forum, something like:
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.
-
Excellent !! It work fine when i use the form id to submit . Thank you ;D
-
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 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\{(.*)\}\}\}\;/