2013-02-13 29 views
1

我想從網站中提取一些數據,但submitbutton只調用第一次在文檔中完成event.after加載第一次提交的頁面文檔完成事件不執行 我的代碼是網頁瀏覽器控制c#只調用下次第一次不工作

private void b_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
    { 
     WebBrowser b = sender as WebBrowser; 
     string response = ""; 
     response = b.DocumentText; 
     HtmlElement links = b.Document.GetElementById("btn1"); 
     links.InvokeMember("click"); 
     checkTrafiicButtonClick = true; 
     MessageBox.Show(""); 
     ***// upto these working and loading second page after that i want to fill data 
      and want to submit but down line is not working and it should be work after  
      loading the page that i submitted how can i do these*** 

     HtmlElement tfrno = b.Document.GetElementById("TrfNo"); 
     tfrno.SetAttribute("value", "50012079"); 
     HtmlElement submitButon = b.Document.GetElementById("submitBttn"); 
     submitButon.InvokeMember("click"); 

    } 
+0

不BTN1點擊加載新一頁? – VladL 2013-02-13 12:06:28

+0

是第一頁btn1點擊執行和第二頁loadig,但我想填寫第二頁的輸入框,並要提交 – dfgv 2013-02-13 12:10:50

+0

只需添加一個變量,以跟蹤你的網頁。 – 2013-02-13 13:20:23

回答

1

根據您的評論,您的代碼將無法正常工作。第一次點擊後,webbroser啓動異步頁面加載。你應該做以下幾點:

private void b_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
    { 
     WebBrowser b = sender as WebBrowser; 
    if(b.Url.AbsoluteUri == "mydomain.com/page1.html") 
    { 
     string response = ""; 
     response = b.DocumentText; 
     HtmlElement links = b.Document.GetElementById("btn1"); 
     links.InvokeMember("click"); 
     checkTrafiicButtonClick = true; 
     MessageBox.Show(""); 
     return; 
    } 
     ***// upto these working and loading second page after that i want to fill data 
      and want to submit but down line is not working and it should be work after  
      loading the page that i submitted how can i do these*** 
    if(b.Url.AbsoluteUri == "mydomain.com//page2.htm") 
    { 
     HtmlElement tfrno = b.Document.GetElementById("TrfNo"); 
     tfrno.SetAttribute("value", "50012079"); 
     HtmlElement submitButon = b.Document.GetElementById("submitBttn"); 
     submitButon.InvokeMember("click"); 
     return; 
    } 
    } 

還要注意,該頁面的某些部分可以從不同的源iframe被加載,例如,所以你必須檢查適當uri

+0

是的,實際上是第二頁的一些數據從iframe的一些另一個url llr如何檢查幀加載是否完成? – dfgv 2013-02-13 13:21:34

+0

@eldhose DocumentCompleted將針對每個加載的url啓動。然後使用fiddler分配幀的地址並檢查它是否已經被加載。 – VladL 2013-02-13 13:39:53

相關問題