简体   繁体   中英

Check box not ticking on HTML WebBrowser VB.Net

I am trying to automatically tick a text box on a vb.net web browser when the page loads the HTML of the check box is as follows

<input checked="checked" class="checkbox" id="order_terms" name="order[terms]" type="checkbox" value="1" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);">

This is what I am trying to use to tick the box but it doesn't seem to work

WebBrowser2.Document.GetElementById("order_terms").SetAttribute("checked", "True")

Any help is appreciated

You can achieve what you seek by doing the following:

Dim Document As mshtml.HTMLDocument = DirectCast(WebBrowser2.Document, mshtml.HTMLDocument)
Dim Input As mshtml.HTMLInputElement = TryCast(Document.getElementById("order_terms"), mshtml.HTMLInputElement)

If Input IsNot Nothing Then
    input.checked = false 'Uncheck the checkbox
End If

(You will need to add a reference to microsoft.mshtml)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM