Question

I have a c# program which has a web browser my program deals with java pages i want it to click a button in a page but the button has no ID or value all i got about it is this code :

  td class="submit">
  <br>
   <button class="fixedSizeBigButton" type="submit">
   </td>

please is there any way to click that button

and for http://watin.sourceforge.net/ i need a code

thanks a lot

Was it helpful?

Solution

Your button has a class name,you can find your button using class name,see this example:

private void Form1_Load(object sender, EventArgs e)
    {
        webBrowser1.DocumentText = "<td class=\"submit\"><br><button   class=\"fixedSizeBigButton\" type=\"submit\"></td>";
        webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
    }

    void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        foreach (HtmlElement btn in webBrowser1.Document.GetElementsByTagName("button"))
        {
            if (btn.GetAttribute("ClassName") == "fixedSizeBigButton")
            {
                btn.InvokeMember("Click");
            }
        }
    }

OTHER TIPS

I found this link when I went looking around.

More looking around leads me to believe you need to look more into the entire Find class itself. I know there are other ways to locate elements.

I'm trying to locate the documentation that will let me construct some code, since I've never actually used this before :-) I'll update if/when I get something more.

Update

Looks like you aren't the only one having similar issues. You can apparently Chain find methods. WatiN - Find HTML Table Which seems rather useful, if you know more about the button's exact location. Using Find.ByClass along with something else, to try to define the button uniquely.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top