2017-09-13 6 views
0

私はすべてが同じクラス持つ3個のダイブタグ持って下:FindElementsコマンドを正しく使用する方法は?

<div class="confirmation-price-summary__price-label confirmation-price-summary__price-label--with-dropdown">(2) Seats</div> 

<div class="confirmation-price-summary__price-label confirmation-price-summary__price-label--with-dropdown">(2) Meals</div> 


<div class="confirmation-price-summary__price-label confirmation-price-summary__price-label--with-dropdown firefinder-match">(1) Extra Baggage</div> 

は私が私の「confirmationResponsiveElements.cs」のページでXPathを経由して、これらのクラスのすべての要素を指すように変数を作成します。

public static By TravelEssentialsBasketLabels => By.XPath("//*[@class='confirmation-price-summary__price-label confirmation-price-summary__price-label--with-dropdown']"); 

「FindElements」メソッドを使用してこれらの要素をすべて検索し、「座席」、「食事」、「余分な手荷物」が含まれていると主張します。私がいることを確認したい場合はAssert.IsTrueが書き込まれることができる方法もcorret FindElementsを使用する方法とは何

public void TravelEssentialsLabelsSideBasket() 
    => _driver.FindElements(ConfirmationResponsiveElements.TravelEssentialsBasketLabels).ToString(); 

、:それは私に死の赤い線を与えているとして、しかし、私はこれを正しく使用する方法がわかりません「座席」、「食事」、「余分な手荷物」が含まれていますか?

おかげ

+0

_driver' 'の種類は何ですか? 'IWebDriver'インターフェースの場合は、それらのメソッドがありません(' RemoteWebDriver'を直接使うことができます)。 –

+0

findElementsは、Web要素のリストを返します。したがって、各要素を繰り返し、GetTextメソッドを使用する必要があります。各要素の値を取得し、期待値と比較します。 – Murthi

+0

@Murthiどうすればいいのですか? – BruceyBandit

答えて

0
List<string> actualoptions = new List<string>(); 
List<string> expectedoptions = new List<string>(); 

expectedoptions.Add("Seats"); 
expectedoptions.Add("Meals"); 
expectedoptions.Add("Extra Baggage"); 

ReadOnlyCollection<IWebElement> links = driver.FindElements(By.XPath("//*[@class='confirmation-price-summary__price-label confirmation-price-summary__price-label--with-dropdown']")); 

foreach(IWebElement link in links) 
{ 
    string text = link.Text; 
    actualoptions.Add(text); 
} 

//then you compare this list with expected value 
if(String.SequenceEqual(actualoptions ,expectedoptions)){ 
    console.write("matching"); 
else 
    console.write("not matching"); 
関連する問題