0

I'm trying to extend Selenium's By class found here.

public static class SeleniumExtensions
{
  public static By Text(this By by, string textToFind)
  {
    return By.XPath("");
  }
}

But I can't find my extension on the By class when I do the above.

canton7
  • 37,633
  • 3
  • 64
  • 77

1 Answers1

0

You need to call it on an instance of the By class, not on the By class itself. For example:

By by = ...;
by.Text("Sales");
Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74
  • I can't create an instance because the constructor is marked as protected. So I'm guessing what I'm trying to do is not possible? –  Mar 04 '20 at 11:30
  • Are not subclasses of By? If not, then, yes, it is not possible, but I can't believe that there aren't. The extension method will apply to any subclasses, as they are By themselves. – Ricardo Peres Mar 04 '20 at 11:31
  • @marceli You can create an instance e.g. by calling `By.XPath(...)`. But that probably isn't what you *want* here – canton7 Mar 04 '20 at 11:31