VB.NET 如何在没有“值”属性的情况下将文本输入到网站文本框中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27089472/
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
VB.NET How to enter text into a website textbox without a "value" attribute
提问by user3740891
I am making a program that finds the source URL of a video from the website, www.clicktoview.org. I can download the captcha it requires, and display it, but I can't solve it with the user's input because the text box on the website doesn't have a value=""attribute.
我正在制作一个程序,可以从网站 www.clicktoview.org 中找到视频的源 URL。我可以下载它需要的验证码,并显示它,但我无法通过用户输入解决它,因为网站上的文本框没有value=""属性。
Here is the relevant part of the HTML code:
这是 HTML 代码的相关部分:
<input type="text" id="recaptcha_response_field" name="recaptcha_response_field">
With this hindrance, is there any way I can input the user's captcha interpretation to the text field?
有了这个障碍,有什么办法可以将用户的验证码解释输入到文本字段中?
My code would be
我的代码是
WebBrowser1.Document.GetElementById("recaptcha_response_field").SetAttribute("value", TextBox2.Text)
but there isn't a valueattribute.
但没有value属性。
N.B. The website is http://clicktoview.org/jbs2xyb89uai
注意网站是http://clicktoview.org/jbs2xyb89uai
Thanks for any help!
谢谢你的帮助!
回答by Roy van der Velde
There isn't anything wrong with your code.
你的代码没有任何问题。
WebBrowser1.Document.GetElementById("recaptcha_response_field").SetAttribute("value", TextBox2.Text)
WebBrowser1.Document.GetElementById("recaptcha_response_field").SetAttribute("value", TextBox2.Text)
should do what you want. Even if a htmlElement doens't have a written value="" field you could still set it.
应该做你想做的。即使 htmlElement 没有写入 value="" 字段,您仍然可以设置它。
Have you checked to see that the GetElementById("recaptcha_response_field")returns a valid htmlElement?
您是否检查过GetElementById("recaptcha_response_field") 是否返回有效的 htmlElement?
Dim htmlElement As HtmlElement = WebBrowser1.Document.GetElementById("recaptcha_response_field")
If htmlElement IsNot Nothing Then
htmlElement.SetAttribute("value",TextBox2.Text)
End If

