vb.net 在 GeckoWebBrowser 上提交 Web 表单?(GeckoFX)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20755971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:14:31  来源:igfitidea点击:

Submit web form on a GeckoWebBrowser? (GeckoFX)

c#html.netvb.netgeckofx

提问by ElektroStudios

There is a properly way to submit a web form using GeckoFXlibrary?

有一种使用GeckoFX库提交网络表单的正确方法吗?

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 WebBrowsercontrol 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.

框架的WebBrowser控件有一种提交 Web 表单的方法,但我找不到任何类似的方法来在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()

采纳答案by Tom

The GeckoFormElement has a submit method.

GeckoFormElement 有一个提交方法。

So something like this:

所以像这样:

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

回答by yasmuru

I can give example in c# :

我可以在 c# 中举例:

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

如果您知道输入标签和登录按钮的 id 值,您可以这样做:

 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 nameof input tags, try this:

如果你知道name输入标签,试试这个:

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 idor nameof input tags and have class name, try this,

如果你不知道任何idname输入标签,并有类名,试试这个,

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();
                }                    
            }
        }