使用awesomium - vb.net将值提交到html文本框

时间:2015-07-04 17:04:23

标签: javascript html vb.net awesomium

我正在使用此代码从列表框中拆分文本:

For Each Item As Object In ListBox1.SelectedItems
                TextBox2.AppendText(Item.ToString + Environment.NewLine)
            Next
            Dim str As String = TextBox2.Text
            Dim leftPart As String = str.Split(":")(0)
            Dim test As String = TextBox2.Text
            Dim phrase As String = test.Substring(test.IndexOf(":"c) + 1)

此代码将值提交到html文本框

WebControl1.ExecuteJavascript("document.getElementById('email').value=""" + leftPart + """;")
                Dim leftpar2 As String
                leftpar2 = phrase
                MsgBox(phrase)
                Try
                    WebControl1.ExecuteJavascript("document.getElementById('pass').value=""" + leftpar2 + """;")
                Catch ex As Exception
                    MsgBox(ex.ToString)
                End Try

id(email)的文本框工作正常 但是另一个(通过)总是空着,我试图弹出(短语)的值,得到正确的值

我试图将字符串分配给变量(短语)

Dim phrase As String = "test"   

它运作正常,有人可以告诉我做错了什么吗?

1 个答案:

答案 0 :(得分:2)

好吧,我已经下载了该组件并且按照您的方式进行了

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If (TextBox1.Text.Length < 3 Or TextBox1.Text.IndexOf(":") < 1) Then
        MsgBox("Please type value in format like {email:password}")
        Return
    End If

    ' Get the values and parse it
    Dim sources As String() = TextBox1.Text.Split(":")

    ' Now, we try to set it to page
    ' pay attention at `document.querySelector('#id')` it should be ID of the element
    WebControl1.ExecuteJavascript(String.Format("document.querySelector('#email').value = '{0}'", sources(0)))
    WebControl1.ExecuteJavascript(String.Format("document.querySelector('#password').value = '{0}'", sources(1)))
End Sub

这是我的登录页面代码(在WebControl组件中加载的页面)

<body>
    <input type="email" id="email" /> 
    <input type="password" id="password" /> 
    <button id="loginButton">Login</button>
</body>

一切似乎都在起作用

您可以运行我的示例:在表单上删除文本框,webcontrol和按钮,将WebControl1.Source设置为“http://cafe-ht.ml/fake/fake-login.html”并在按钮单击时复制处理程序

enter image description here