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.