如何正确使用FindElements命令?

时间:2017-09-13 07:30:52

标签: c# selenium

下面我有三个潜水标签都有相同的类:

<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>

我创建了一个变量,通过我的&#39; confirmationResponsiveElements.cs&#39;中的xpath指向所有这些类元素。页:

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

我想使用&#39; FindElements&#39;找到所有这些元素的方法,然后断言它们包含&#39; Seats&#39;&#39; Meals&#39;和&#39;额外行李&#39;。但是我不确定如何正确使用它,因为它给了我死亡的红线:

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

使用FindElements的正确方法是什么?如果我想检查它是否包含&#39; Seats&#39; ,&#39;用餐&#39;和&#39;额外行李&#39;?

由于

1 个答案:

答案 0 :(得分: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");