简体   繁体   English

C#HTML获取所有复选框并随机按下

[英]C# HTML get all checkboxes and press them randomly

I am desperate for help. 我迫切需要帮助。 I have tried to get all checkboxes from a website and press them randomly. 我试图从网站上获取所有复选框并随机按下它们。 The random function should choose one of the 3 following checkboxes in the list of all checkboxes. 随机函数应在所有复选框的列表中选择以下三个复选框之一。 Something like this : it chooses randomly just one checkbox from checkbox 1 to checkbox 4. Then it chooses another checkbox randomly from checkbox 4 to checkbox 7. 这样的事情:它从复选框1到复选框4随机选择一个复选框。然后从复选框4到复选框7随机选择另一个复选框。

I already have problems getting all the checkboxes and check like 1 of them. 我已经在获取所有复选框并像其中1个一样进行检查时遇到了问题。

This is the HTML code for 1 checkbox 这是1个复选框的HTML代码

<input id="m_embeddedProfileControl_m_questionSheet_ctl02_1012343_3056092_0"         type="checkbox" name="m_embeddedProfileControl$m_questionSheet$ctl02$ctl00$1012343_3056092"  onclick="javascript:return   ChangeCheckBoxAnswerValue(C1012343_3056092,3056092,'',1012343,true);">

And this is my try so far in visual studio 2013 到目前为止,这是我在Visual Studio 2013中的尝试

HtmlElementCollection test = wb.Document.GetElementsByTagName("input");
foreach (HtmlElement blub in test)
{
    if (blub.GetAttribute("type").Equals("checkbox"))
    {
        blub.InvokeMember("onclick");
    }
}

How about something like this: 这样的事情怎么样:

private void CheckOneRandomly(HtmlElement[] chks)
{
  chks[Convert.ToInt32(Math.Random()*chks.length)-1].InvokeMember("onclick");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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