2017-09-13 69 views
0

下面我有三個潛水標記,都具有相同的類:如何正確使用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> 

我創建了一個變量通過XPath來指向所有這些類的元素在我的'confirmationResponsiveElements.cs頁面:

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

我想使用'FindElements'方法來查找所有這些元素,然後聲明它們包含'座位','膳食'和'額外行李'。但是我不知道如何正確地使用這個,因爲它是給我死亡的紅線:

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

什麼是使用FindElements的corret途徑,也是,怎麼能如果我要檢查Assert.IsTrue應該寫成它包含'座位','餐食'和'額外行李'?

感謝

+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"); 
相關問題