Closed otto-gebb closed 7 years ago
A change like this in JavaScriptBy.cs
could fix the problem.
@@ -48,7 +48,11 @@ public JavaScriptBy(string script, params object[] args)
public override IWebElement FindElement(ISearchContext context)
{
ReadOnlyCollection<IWebElement> elements = this.FindElements(context);
- return elements.Count > 0 ? elements[0] : null;
+ if (elements.Count == 0)
+ {
+ throw new NoSuchElementException($"Unable to locate element: {{ {Description} }}.");
+ }
+ return elements[0];
}
/// <summary>
Thanks for the contribution ! Now we have the same behavior than Selenium WebDriver.
As this introduced a breaking change, it will be available in the next major release.
Available with v0.10
Consider the following console application. The comments explain the observed and the expected behavior.
Diagnosing
NullReferenceException
s is not very convenient. Compare it to the exception thrown when searching by an unknown id: