Frage

There is a properly way to submit a web form using GeckoFX library?

This is what I'm doing to fill a web form and submit the form, but...well, I'm not submitting, I'm just clicking on the last button of the page and I think that can't be the properly way to do it...

Framework's WebBrowser control has a method to submit a web form but I can't find any similar method to properly submit a web form on a GeckWebBrowser.

Dim doc = GeckoWebBrowser1.Document

doc.GetElementById("id_username").
    SetAttribute("value", CStr(MyUsername))

doc.GetElementById("id_password").
    SetAttribute("value", CStr(MyPassword))

doc.GetElementsByTagName("input").
    Last.Click()
War es hilfreich?

Lösung

The GeckoFormElement has a submit method.

So something like this:

(GetElementByTagName("form").First() as GeckoFormElement).submit()

Andere Tipps

I can give example in c# :

If you know id value for input tags and login button , you can do this:

 GeckoInputElement username = new GeckoInputElement(geckoWebBrowser1.Document.GetElementById("Username_ID").DomObject);
 GeckoInputElement Passwd = new GeckoInputElement(geckoWebBrowser1.Document.GetElementById("passwd_ID").DomObject);
 GeckoInputElement Loginbutton = new GeckoInputElement(geckoWebBrowser1.Document.GetElementById("login_button_ID").DomObject);
 username.Value = "username";
 Passwd.Value = "password";
 Loginbutton.Click();

and if you know name of input tags, try this:

GeckoInputElement username = new GeckoInputElement(geckoWebBrowser1.Document.GetElementsByName("email")[0].DomObject);
GeckoInputElement password = new GeckoInputElement(geckoWebBrowser1.Document.GetElementsByName("pass")[0].DomObject);
GeckoInputElement login = new GeckoInputElement(geckoWebBrowser1.Document.GetElemntByName("login_name")[0].DomObject);
username.Value = "username";
password.Value = "password";
login.Click();

and if you dont know any id or name of input tags and have class name, try this,

GeckoNodeCollection nod = geckoWebBrowser1.Document.GetElementsByClassName("classname");
        foreach (GeckoNode node in nod)
        {
            if (NodeType.Element == node.NodeType)
            {

                try
                {
                    GeckoInputElement ele = (GeckoInputElement)node;
                    ele.Click();
                }
                catch (Exception ex)
                {
                    string ep = ex.ToString();
                    GeckoHtmlElement ele = (GeckoHtmlElement)no2;
                    ele.Click();
                }                    
            }
        }  
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top