2016-08-07 3 views
1

私は時々存在しないコード行を持っています。ここでヌルラインはどのように受け入れますか?

HtmlElement Pend = webBrowser1.Document.GetElementById("ctl00_cphRoblox_AlreadyRequestedInvite"); 

は今、私が助けを必要とするものに私のコード

string PendT; 
webBrowser1.Document.GetElementById("ctl00_cphRoblox_JoinGroup").InvokeMember("click"); 
HtmlElement Pend = webBrowser1.Document.GetElementById("ctl00_cphRoblox_AlreadyRequestedInvite"); 
PendT = Pend.InnerText; 
Debug.WriteLine(PendT); 

if (PendT == "Join Pending") 
{ 
    Debug.WriteLine("Join Pending"); 
    Value = 1; 
} 

の残りの部分での保留がnullで、私はPendT = Pend.InnerText;を行うために行くとき、私はSystem.NullReferenceExceptionを取得し、時にはあります。それはおそらく、Pendを見つけることができないからでしょう。 nullの場合、文字列値を保留に割り当てることができますか?私は試しました

if (webBrowser1.Document.GetElementById("ctl00_cphRoblox_AlreadyRequestedInvite").InnerText != null) 
{ 
Debug.WriteLine("Join Pending"); 
Value = 1; 
} 

それは働いていません。

+0

「PendT = Pend == null」のようなものですか? "Oh noez":PendT.InnerText; '? – stuartd

答えて

0

Pendが取得された後にnullであるかどうかを確認できます。あなたがチェックされている場合は、tahtで何をしますか?

string PendT; 
webBrowser1.Document.GetElementById("ctl00_cphRoblox_JoinGroup").InvokeMember("click"); 
HtmlElement Pend = webBrowser1.Document.GetElementById("ctl00_cphRoblox_AlreadyRequestedInvite"); 

if(Pend != null) 
{ 
    PendT = Pend.InnerText; 
    Debug.WriteLine(PendT); 

    if (PendT == "Join Pending") 
    { 
    Debug.WriteLine("Join Pending"); 
    Value = 1; 
    } 
} 
else 
{ 
    // do something here 
} 
+0

作品の並び順: PendT = "Join Pending"になってもまだそれはそうではないと思っていますが、他にもコードがありますが、私はもうエラーは出ません。 – Bootsie123

+0

私のプログラムで要素がnullであるかどうかを判断するボタンをクリックした後にチェックすることができますか?そして、ページを更新するのに十分な時間がありませんか? – Bootsie123

関連する問題