2012-10-18 3 views
2

일부 페이지를로드하는 WebBrowser 컨트롤이있는 봇을 만들고 있습니다. 내 봇이 체크하지 않으려는 체크 박스가 있습니다.코드를 사용하여 HTML 체크 박스 선택 취소

HtmlElementCollection elc = this.BotBrowser.Document.GetElementsByTagName("input"); 
foreach (HtmlElement el in elc) 
{ 
    if (el.GetAttribute("value").Equals("Leishmania mexicana")) //to uncheck Leishmania mexicana checkbox 
    { 
     el.InvokeMember("click"); 

    } 
} 

을하지만 때때로 페이지를로드 100 회보다 더 많은 작업을 수행 할 수있는이 로봇으로 확인란이-검사를 다시 때문에 완벽하지는 같다 : 지금은이 코드를 사용하고 있습니다.

<input type="checkbox" class="jstree-real-checkbox" id="array(BlastDatabaseOrganism)" name="array(BlastDatabaseOrganism)" value="Leishmania mexicana" checked="checked"> 

null로 속성을 확인의 I이 속성을 제거하거나 설정할 수있는 방법이 있나요 :

여기에 체크 박스의 HTML 태그는?

답변

5

이이

el.SetAttribute("checked", null); 
+1

감사합니다. 'InvokeMember ("click")'보다 훨씬 낫다. – Jack

1

첫 번째 가져 오기 mshtml (Microsoft 탭 아래의 Microsoft Html Object Library) 네임 스페이스를 프로젝트에 가져옵니다. 다음이

using mshtml; 


HtmlElementCollection elc = this.BotBrowser.Document.GetElementsByTagName("input"); 
foreach (HtmlElement el in elc) 
{ 
     if (el.GetAttribute("value").Equals("Leishmania mexicana")) //to uncheck Leishmania mexicana checkbox 
        { 
          HTMLInputElement elm = el.DomElement as HTMLInputElement; 
          [email protected] = false; 

        } 
} 
+0

내가이 –

+0

이 너무 라디오 버튼을 위해 작동 할 시도 할 것이다보십시오 사용합니다. – aliassce

+0

어떻게이 구문을'. @ checked'로 정의 할 수 있습니까? 제게 알려주십시오 ... –

관련 문제