2017-08-30 9 views
-1

内の特定の文字が含まれています:は私がHTMLタグを取得する場所を、以下の方法を持っているセレン

public void CheckEmailDisplayed() 
    { 
     var email = _driver.FindElement(ConfirmationResponsiveElements.ViewEmail); 

    } 

ViewEmailは以下の通りです:

public static By ViewEmail => By.ClassName("confirmation-banner__text"); 

それはに対応してHTML :私は何をしたいか

<div class="confirmation-banner__text firefinder-match"> 
<p> 
We've sent an email to 
<strong>[email protected]</strong> 
</p> 
<p> 
</div> 

は、テキスト詐欺かどうかを確認するために、変数emailを使用することができるようですは@になります。これは、電子メールアドレスが表示されているかどうかを判断するのに役立ちます。これはどのように達成できますか?

おかげ

+0

参照:[Xはどのように行うのですか?](https://meta.stackoverflow.com/questions/253069/whats-the--new-current-close-reason-for-how-do-i-do- x)SOに関する期待は、質問をするユーザーが自分の質問に答えるだけでなく、その研究、コードの試行、結果を共有するということです。これは、時間をかけて自分自身を助けようとしていることを示しています。明白な回答を繰り返さないようにしてくれています。そして、より具体的で適切な答えを得ることができます。参照:[ask] – JeffC

答えて

1

オプション1:@記号をチェック

 string email = "[email protected]"; 
     if (email.Contains("@")) 
     { 
      // code here 
     } 

オプション2:検証メールアドレスオプション2を使用する方法

public static bool IsEmail(string emailToValidate) 
{ 
    if (string.IsNullOrEmpty(emailToValidate)) return true; 

    return Regex.IsMatch(emailToValidate, @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); 
} 

 string email = "[email protected]";    
     if (IsEmail(email)) 
     { 
      // valid email address 
     } 
     else 
     { 
      // not a valid email address 
     } 
0

別の定義を追加することができます

public static By ViewEmailAddress => By.TagName("strong"); 

その後

var emailAddress = emai.FindElement(ConfirmationResponsiveElements.ViewEmailAddress); 
var emailAddressText = emailAddress.Text; 

を使用し、あなたがemailAddressTextにしたい異なる操作を行うことができます。 @を持つか、電子メールのパターンチェック

0

のようなより複雑な検証を行うことを確認するようにあなたは

あなたはまた、(ただし読みにくく)正規表現を使用することができますIndexOfメソッドに

bool found = Value1.IndexOf("abc", 0, 7) != -1; 

OR

を使用することができます

string regex = "^.{0,7}abc"; 

System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(regex); 
string Value1 = "sssddabcgghh"; 

Console.WriteLine(reg.Match(Value1).Success); 

出典: - How to determine if string contains specific substring within the first X characters

関連する問題