2015-01-05 8 views
0

什麼我試圖要做的就是點擊iframe程序看起來像這樣點擊驗證碼iframe的編程是不工作

enter image description here

html代碼:

<div class="g-recaptcha" data-sitekey="6Lf3v8wSAAAAABVuu8qFKDtsvc0ILPoyUBVRToA9" style="width: 40%; margin: 0 auto;"> 

    <div> 
     <div style="width: 304px; height: 78px;"> 
      <iframe id="I0_1420487033543" width="304" height="78" frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" style="" tabindex="0" vspace="0" name="I0_1420487033543" src="https://www.google.com/recaptcha/api2/anchor?k=6Lf3v8wSAAAAA…=http%3A%2F%2F&pfname=&rpctoken=24572959"></iframe> 
     </div> 
     <textarea id="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 80px; border: 1px solid #c1c1c1; margin: 0px; padding: 0px; resize: none; display: none; " name="g-recaptcha-response" dir="ltr"></textarea> 
    </div> 

</div> 

,什麼我試圖要做的是:

private void web_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
     { 
      if (this.Web.ReadyState != WebBrowserReadyState.Complete) 
       return; 


      this.Web = sender as WebBrowser; 


      var theElementCollection = Web.Document.Body.GetElementsByTagName("iframe"); 

      for (int i = 0; i < theElementCollection.Count; i++) 
      { 
       HtmlElement curElement = theElementCollection[i]; 

       if (curElement.Id != null && curElement.Id.StartsWith("I0_")) 
       { 
        curElement.InvokeMember("click"); 

       } 
      } 
     } 

但它不工作,我怎麼能解決這個問題?

+1

大概內置瀏覽器安全是阻斷點擊(域是不同的)。 – MikeTheLiar

+0

@mikeTheLiar:是的,頂級文檔不應該能夠自動化iframe的內容。但是,儘管如此,如果這是可能的,那麼這個驗證碼將是無用的,驗證碼的整點是你不能自動化它們。 –

回答

0

我是能夠實現類似於您一些地方尋找利用硒和下面的代碼:

private static void verifySites(string username, string password) 
{ 
    using (var ffox = new FirefoxDriver() 
    { 
     /// code to login once logged in 
     var recaptcha = ffox.FindElementByTagName("iframe"); 
     recaptcha.Click(); 
    } 
}