Skip to content

Commit e4f0c0a

Browse files
committed
Improve experience with By
1 parent aa8be29 commit e4f0c0a

File tree

1 file changed

+12
-5
lines changed
  • dotnet/src/webdriver

1 file changed

+12
-5
lines changed

dotnet/src/webdriver/By.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public partial class By
4848
/// <summary>
4949
/// Initializes a new instance of the <see cref="By"/> class.
5050
/// </summary>
51-
/// <remarks>
52-
/// When using this constructor, make sure to set the <see cref="FindElementMethod"/> or the <see cref="FindElementsMethod"/> properties.
53-
/// </remarks>
5451
protected By()
5552
{
5653
}
@@ -329,7 +326,12 @@ public static By CssSelector(string cssSelectorToFind)
329326
/// <returns>The first matching <see cref="IWebElement"/> on the current context.</returns>
330327
public virtual IWebElement FindElement(ISearchContext context)
331328
{
332-
return this.FindElementMethod(context);
329+
if (this.FindElementMethod is not { } findElementMethod)
330+
{
331+
throw new InvalidOperationException("FindElement method not set. Override the By.FindElement method, set the By.FindElementMethod property, or use a constructor that sets a query mechanism.");
332+
}
333+
334+
return findElementMethod(context);
333335
}
334336

335337
/// <summary>
@@ -340,7 +342,12 @@ public virtual IWebElement FindElement(ISearchContext context)
340342
/// matching the current criteria, or an empty list if nothing matches.</returns>
341343
public virtual ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
342344
{
343-
return this.FindElementsMethod(context);
345+
if (this.FindElementsMethod is not { } findElementsMethod)
346+
{
347+
throw new InvalidOperationException("FindElements method not set. Override the By.FindElements method, set the By.FindElementsMethod property, or use a constructor that sets a query mechanism.");
348+
}
349+
350+
return findElementsMethod(context);
344351
}
345352

346353
/// <summary>

0 commit comments

Comments
 (0)