[問題] [C/C++] webBrowser1執行問題

看板C_and_CPP (C/C++)作者 (毛毛)時間10年前 (2015/11/23 14:44), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
開發平台(Platform):VC++ 問題(Question): 當執行login()的function時,會fail在webBrowser1->Document->GetElementById("Email")->SetAttribute("value",useraccount); 因為感覺webBrowser1並沒有轉跳到要輸入帳號密碼的那一個page.基本上這兩個function 都是沒問題的!因為分別寫成兩個botton執行是沒問題的. 當按下第一個botton可以看到webBrowser1物件有跳到要輸入帳號密碼那個頁面,然後按下 第二個botton就可以進入. 可是我把他寫在同一個function裡面,然後讓我的程式直接去跑就會fail.請問我少了什麼 動作造成轉跳沒有成功而造成輸入帳密有問題呢? 預期的正確結果(Expected Output): 主線程先執行gotowebmail()後,最後再執行login().然後可以正確登入 錯誤結果(Wrong Output): 當執行完gotowebmail()後,進入login()的function時,會在 webBrowser1->Document->GetElementById("Email")->SetAttribute("value",useraccount); 出錯!因為單步debug時,看到web並沒跳過去login頁面,所以造成找不到useraccount的關鍵字. 可是我將gotowebmail()與login分別寫兩個botton卻沒有這樣的問題! 有想過是不是時間的問題,所以我在gotowebmail()與login中間有加入一個loding()的function 去確認是否有讀取完成.但是,單步去看loding裡面的code時,看到有complete.但問題依舊是 在同樣的地方出錯.請問我該如何改才能達到我希望一鍵完成呢? 程式碼(Code): 主線程: void Excuit() { gotowebmail(); loding(); login(); } ===============================gotowebmail()============================= void gotowebmail() { Sleep(500); HtmlDocument^ htmlmain = webBrowser1->Document; Sleep(500); for(int i = 0;i < htmlmain->All->Count;i++) { HtmlElement^ he = htmlmain->All[i]; if(he->TagName->Contains("SPAN")) { if (he->InnerText == "webmail") { he->InvokeMember("Click"); break; } } } } ================================login()================================ void login() { String^ useraccount; String^ userpassword; useraccount = btn_account->Text; userpassword = btn_password->Text; //輸入帳密 HtmlDocument^ htmlmain_1 = webBrowser1->Document; webBrowser1->Document->GetElementById("Email")->SetAttribute("value",useraccount); webBrowser1->Document->GetElementById("Passwd")->SetAttribute("value",userpassword); for(int y = 0;y < htmlmain_1->All->Count;y++) { HtmlElement^ he_1 = htmlmain_1->All[y]; if(he_1->TagName->Contains("INPUT")) { if(he_1->GetAttribute("value") == "登入") { he_1->InvokeMember("Click"); break; } } } } =================================loading================================= public: void loading() { while (!(webBrowser1->ReadyState == WebBrowserReadyState::Complete)) { Application::DoEvents(); } } ========================================================================= -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.120.53.53 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1448261096.A.8EA.html

11/23 23:27, , 1F
已解決
11/23 23:27, 1F
文章代碼(AID): #1MKhNeZg (C_and_CPP)
文章代碼(AID): #1MKhNeZg (C_and_CPP)