简体   繁体   中英

C# web browser click on text

I want to click the text "Check All" on website using web browser method. I don't get any idea how to do it. This is HTML code of the website:

<a onclick="checkAll(document.myform.list)" href="#">Check all</a>
<a onclick="uncheckAll(document.myform.list)" href="#">Uncheck all</a>
<input type="hidden" value="t2ah9m" name="check">

My code to click on it:

webBrowser1.Document.All.GetElementsByName("check")[0].SetAttribute("Value", "Click");

But failed..

this is the sript:

function checkAll(field)
{   for (i = 0; i < field.length; i++)  field[i].checked = true ;   }

function uncheckAll(field)
{for (i = 0; i < field.length; i++) field[i].checked = false;   }

You can use jquery to select all the input types checkbox

eg: Your form

<form>
<input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car 
</form>

Your links

<a id="checkAll" href="#">Check all</a>
<a id="uncheckAll" href="#">Uncheck all</a>

Your javascript

$("#checkAll").click(function() {
    $('type').find('checkbox').prop('checked', true);
});

$("#uncheckAll").click(function() {
    $('type').find('checkbox').prop('checked', false);
});

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