Skip to content

Instantly share code, notes, and snippets.

@yashaka
Created June 25, 2020 13:48
Show Gist options
  • Save yashaka/61a6e2771312e07c42fc6eeadc62ea50 to your computer and use it in GitHub Desktop.
Save yashaka/61a6e2771312e07c42fc6eeadc62ea50 to your computer and use it in GitHub Desktop.
Bills.Tests/Core/SeleneCollectionExtensions.cs
using OpenQA.Selenium;
using static NSelene.Selene;
using NSelene;
using OpenQA.Selenium.Interactions;
using System;
using NSelene.Conditions;
using System.Linq;
using System.Collections.Generic;
namespace Bills.Tests.Core
{
public static class SeleneCollectionExtensions
{
public static int IndexOfElementBy(this SeleneCollection collection, Condition<SeleneElement> condition, int amongExpectedOfNumber=-1)
{
if (amongExpectedOfNumber>0)
{
collection.Should(Have.Count(amongExpectedOfNumber));
}
collection.FindBy(condition).Should(Be.InDom);
return ((IEnumerable<SeleneElement>)collection)
.Select((Value, Index) => new {Value, Index})
.Single(its => condition.Apply(its.Value))
.Index;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment