使用 awesomium 将值提交到 html 文本框 - vb.net
Submit value to html textbox with awesomium - vb.net
我正在使用此代码从列表框中拆分文本:
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(电子邮件)的文本框工作正常
但另一个 (pass) 总是空的,我尝试弹出 (phrase) 的值,它得到正确的值
我尝试将字符串分配给变量(短语)
Dim phrase As String = "test"
它工作正常,有人可以告诉我哪里做错了吗?
好的,我已经下载了那个组件并按照您的方式进行了
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>
一切正常
您可以运行我的示例:将文本框、网页控件和按钮放在表单上,将WebControl1.Source设置为“http://cafe-ht.ml/fake/fake-login.html”并在按钮单击时复制处理程序
我正在使用此代码从列表框中拆分文本:
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(电子邮件)的文本框工作正常
但另一个 (pass) 总是空的,我尝试弹出 (phrase) 的值,它得到正确的值
我尝试将字符串分配给变量(短语)
Dim phrase As String = "test"
它工作正常,有人可以告诉我哪里做错了吗?
好的,我已经下载了那个组件并按照您的方式进行了
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>
一切正常
您可以运行我的示例:将文本框、网页控件和按钮放在表单上,将WebControl1.Source设置为“http://cafe-ht.ml/fake/fake-login.html”并在按钮单击时复制处理程序