2017-10-15 12 views
0

GeckoWebBrowser가있는 Windows 응용 프로그램에서 작업 중이며 코드를 통해 보안 문자의 확인란을 선택하려고합니다. Programmaticaly 이미 html 요소를 가져오고 설정할 수 있지만이 확인란에는 연결할 수 없습니다. 페이지의 어느 위치에서나 찾을 수 없습니다. captcha를 분열 시키거나 해결하려고 시도하지 않고 체크 박스 요소를 확인한 후 확인하십시오. 그런 간단한.GeckoWebBrowser Captcha 체크 박스를 표시하는 방법 (C# Windows 양식)?

내가 지금 알고있는 무엇 :

파이어 폭스 관리자에서 나는 enter image description here 어떤 확실한 정보를 볼 수 있습니다 보안 문자는, 제목 = "위젯 reCAPTCHA를"있는 iframe에 폭 = 304 높이 = 78 .

체크 박스 요소 (iframe을 내부에)이 점에 : 지금 enter image description here

, 이것이 내가 가진 다른 방법으로 ID, 범위, 사업부 및 클래스를 찾고, 체크 박스를 얻으려고하는 방법이다 주요 문서

  //looking all elements into main Document (around 1300 elements) 
      GeckoElementCollection collection = geckoWebBrowser1.Document.GetElementsByTagName("*"); 
     foreach (GeckoHtmlElement elem in collection) 
     { 
      string id = elem.Id; 
      if (id == "recaptcha-anchor") 
      { 
       string myId = "this is my ID";   //never find this ID! 
      } 
      //just for debug 
      string LocalName = elem.LocalName; 
      string OuterHtml = elem.OuterHtml; 
      string TagName = elem.TagName; 
      string TextContent = elem.TextContent; 
      string role = elem.GetAttribute("role"); 
      string value = elem.GetAttribute("value"); 
     } 

에는 성공 ...

먼저, 그래서, 주요 문서에서 나는 ID로 아무것도 찾을 수 없습니다.

다음은 iframe에보고 :

 //get the iframe works well 
     foreach (GeckoIFrameElement iframe in geckoWebBrowser1.Document.GetElementsByTagName("iframe")) 
     { 
      //get main info about the iframe - ok 
      string title = iframe.GetAttribute("title"); 
      if (title != null && title.ToLower().Contains("captcha")) //got "recaptcha widget" 
      { 
       int x = iframe.OffsetLeft; 
       int y = iframe.OffsetTop; 
       int width = Convert.ToInt32(iframe.Width); 
       int height = Convert.ToInt32(iframe.Height); 
      } 

      //inside the iframe, get all elements --> but always return null 
      Gecko.Collections.IDomHtmlCollection<GeckoElement> collection2 = iframe.GetElementsByTagName("*"); 
      foreach (GeckoHtmlElement elem in collection2) 
      { 
       string id = elem.Id; 
       string LocalName = elem.LocalName; 
       string OuterHtml = elem.OuterHtml; 
       string TagName = elem.TagName; 
       string TextContent = elem.TextContent; 
       string role = elem.GetAttribute("role"); 
       string value = elem.GetAttribute("value"); 
      } 

      //foreach (GeckoHtmlElement elem in iframe.GetElementsByTagName("*"))    //get no elements 
      //foreach (GeckoHtmlElement elem in iframe.GetElementsByTagName("input"))   //get no elements 
      //foreach (GeckoHtmlElement elem in iframe.GetElementsByTagName("div"))   //get no elements 
      foreach (GeckoHtmlElement elem in iframe.GetElementsByTagName("span"))   //get no elements 
      { 
       string id = elem.Id; 
       string LocalName = elem.LocalName; 
       string OuterHtml = elem.OuterHtml; 
       string TagName = elem.TagName; 
       string TextContent = elem.TextContent; 
       string role = elem.GetAttribute("role"); 
      } 
     } 

그래서, 시도 및 오류를 많이 후 나는 체크 박스 요소를 얻을 수 없다,하지만 난 위치와 크기처럼 보안 문자 상자에 대한 몇 가지 정보를 얻을 수 있습니다 , 제목이 100 %는 아니지만, Firefox에서는 title = "widget recaptcha"와 GeckoWebbrowser title = "recaptcha widget"... 엽기적인 기괴함.

누구는 내가 부족 무엇이나 내가 잘못 뭘하는지? 일부 sugestion있다 :-(... 나를 미치게됩니다 도 iframe을 모든 HTML 요소를 얻을 수있는 방법이 있습니다 또는 전체 요소 트리?

내가 할 노력하고있어 무엇을 할 수 있습니까?

감사합니다 사전에!

답변

1

이 GeckoWin의 Frames 속성을 사용하여 현재 페이지의 모든 iframe이 요소를 찾으려면 다우 :

// this will return a collecton of all frames 
var iframes = Browser.Window.Frames; 

나는 당신이 당신의 브라우저의 DocumentCompleted 이벤트의 핸들러에서이 일을 권 해드립니다. 그런 다음이 프레임을 반복합니다. 각 프레임에는 자체의 모든 요소에 대한 컨테이너 인 자체 Document 요소가 있습니다. 귀하의 보안 문자가 있어야합니다. 그럼 당신은 아마 체크 박스와 DIV을 찾아, 그것을 클릭합니다, 그래서 코드는 다음과 looke 것이다 : 나는 GeckoHtmlElement을 사용하고

foreach (var iframe in iframes) 
{ 
    var doc = iframe.Document; 
    if (doc == null) 
     continue; 

    var elements = doc.GetElementsByClassName("your_name"); 

    foreach (var element in elements) 
    { 
     // get the div and validate it 
     var myDiv = element as GeckoDivElement; 
     if(myDiv == null || !myDiv.Id.Equals("your_checkbox_id", StringComparison.InvariantCultureIgnoreCase)) 
      continue; 

     myDiv.Click(); // click your checkbox 
     break; 
    } 
} 
+0

대신 GeckoDivElement합니다. 감사! –