I'm trying to invoke the click event of a HTML button that lives inside a WebBrowser control in my Windows Forms application. I have successfully clicked many buttons before(I needed to click a button, which i did, but then their was another button that asked me to confirm an action. and i cant seem to click it!) this button has the same exact HTML as the button prior to it, however i cant seem to click it with the same coding, I don't get an error, just nothing happens. So, my objective: Get to the end target just like a human would. (no direct links, but the links that it would take a human to do it). Next have the program fill in a form, based on my windows form application's textboxes. Next, click a radio-button(bubbled). Click submit, And Finally click confirm. I managed to do all of this except clicking confirm! Im not sure why that is!
OK, here is the code:
private void button5_Click(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "Making human-like decisions...";
toolStripProgressBar1.Value = 50;
wb.Navigate((boturl.Text) + "/dorf1.php");
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
wb.Navigate((boturl.Text) + "/dorf2.php");
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
wb.Navigate((boturl.Text) + "/build.php?id=39");
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
wb.Navigate((boturl.Text) + "/a2b.php");
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
toolStripProgressBar1.Value = 70;
toolStripStatusLabel1.Text = "Selecting Troops";
HtmlElement xcord = wb.Document.All["xCoordInput"];
xcord.SetAttribute("value", (textBox1.Text));
HtmlElement ycord = wb.Document.All["yCoordInput"];
ycord.SetAttribute("value", (textBox2.Text));
toolStripProgressBar1.Value = 90;
toolStripStatusLabel1.Text = "Selecting Coords'";
foreach (HtmlElement hem in wb.Document.All)
{
if (hem.Name == "c" && hem.GetAttribute("value") == "3")
{
hem.InvokeMember("click");
break;
}
}
HtmlElement unit1 = wb.Document.All["t1"];
unit1.SetAttribute("value", (textBox4.Text));
HtmlElement unit2 = wb.Document.All["t2"];
unit2.SetAttribute("value", (textBox5.Text));
HtmlElement unit3 = wb.Document.All["t3"];
unit3.SetAttribute("value", (textBox6.Text));
HtmlElement unit4 = wb.Document.All["t4"];
unit4.SetAttribute("value", (textBox7.Text));
HtmlElement unit5 = wb.Document.All["t5"];
unit5.SetAttribute("value", (textBox8.Text));
HtmlElement unit6 = wb.Document.All["t6"];
unit6.SetAttribute("value", (textBox9.Text));
HtmlElement unit7 = wb.Document.All["t10"];
unit7.SetAttribute("value", (textBox10.Text));
HtmlElement unit8 = wb.Document.All["t9"];
unit8.SetAttribute("value", (textBox11.Text));
HtmlElement unit9 = wb.Document.All["t8"];
unit9.SetAttribute("value", (textBox12.Text));
HtmlElement unit10 = wb.Document.All["t7"];
unit10.SetAttribute("value", (textBox13.Text));
HtmlElement sendraid2 = wb.Document.All["btn_ok"];
sendraid2.InvokeMember("click");
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
HtmlElement sendraid3 = wb.Document.All["btn_ok"];
sendraid3.InvokeMember("click");
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
toolStripProgressBar1.Value = 100;
if (toolStripProgressBar1.Value == 100)
{
toolStripStatusLabel1.Text = "Sending...";
toolStripProgressBar1.Value = 0;
toolStripStatusLabel1.Text = "Ready To Bot.";
}
if (this.textBox3.Text != "")
{
int theInterval = 0;
if (Int32.TryParse(this.textBox3.Text, out theInterval))
{
if (theInterval != 0)
{
theTimer.Interval = theInterval * 10000;
theTimer.Start();
}
}
}
else
{
btn_StopTimer_Click(null, null);
}
}
and here is the button's HTML(this is the button i cannot seem to click):
<button type="submit" value="ok" name="s1" id="btn_ok"><div class="button-container"><div class="button-position"><div class="btl"><div class="btr"><div class="btc"></div></div></div><div class="bml"><div class="bmr"><div class="bmc"></div></div></div><div class="bbl"><div class="bbr"><div class="bbc"></div></div></div></div><div class="button-contents">confirm</div></div></button>
Thanks!