2013-10-23 257 views
0

這是在Visual Studio Express的桌面C#應用程序2012web瀏覽器無法點擊按鈕登錄網站

我想使用WebBrowser控件自動登錄到不同的網站,但我無法找到登錄按鈕併爲該特定網站發出「點擊」。我能夠找到用戶名和密碼字段併爲那些沒有問題的人填充值。這只是我似乎無法發出'點擊'來完成登錄。

有問題的網站是https://www.my.telstra.com.au/myaccount/home?red=/myaccount/

使用谷歌Chrome瀏覽器我檢查的登錄按鈕的代碼,發現這個:

< DIV CLASS = 「提交submit_buttons形式排」> <一類= 「BTN-藍色」 稱號= 「按鈕登錄我的帳戶」 HREF = 「JavaScript的:無效(0)」>登錄 </DIV>

任何幫助將不勝感激!

米克

注意到這個問題是一個後續的與相同的網站WebBrowser website timeout 這是成功回答了前面的問題。

回答

1

喜歡找

HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("a"); 
//this vill take elements tagget with <a></a> 

按鈕,然後發送單擊

//first find your submit button in <a> tags with the tags diffrence from other <a>'s 
//on your code it seem your tags title difrent than other <a>'s 
HtmlElement yourTag; 
foreach(HtmlElement o in elements) 
{ 
    if(o.GetAttribute("title")=="Button to Login to My Account") 
    { 
     yourTag=o; 
    } 
} 
yourTag.InvokeMember("click"); 

,或者你可以找到任何不同勢屬性 您的按鈕,這應該工作

而如果你的標籤有沒有任何別的區別,你可以找到div包含它的類屬性和訪問它的孩子,併發送點擊

myHtmlElement.Children[index].InvokeMember("click"); 
+0

你可以通過刪除你的標籤來改善你的代碼,並調用if裏面的成員來調用'o.InvokeMember(「Click」);'用conntion with break;'調用。此外,你應該檢查你的代碼,有一些拼寫錯誤。除此之外:好。 –

+0

謝謝TC和丹尼爾 - 這個作品非常出色! HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName(「a」); (o.GetAttribute(「title」)==「Button to Login to My Account」) { o .vokeMember(「Click」); 休息; } } –