testingrequired / webdriver

A webdriver library
MIT License
0 stars 0 forks source link

Align WebElement element query typings to Browser #22

Open kyleect opened 4 years ago

kyleect commented 4 years ago
 async findElement<T extends WebElement>(
    by: By,
    WebElementClass?: Constructor<T>
  ): Promise<T> {
    const elementId = await this.driver.findElement(by);

    if (typeof elementId === "undefined") {
      throw new ElementNotFoundError(
        `Unable to find element using ${by.using}: ${by.value}`
      );
    }

    const WebElementImplementation: Constructor<T> = (WebElementClass ||
      WebElement) as any; // TODO: This is, admittedly, a hack

    const element: T = new WebElementImplementation(this, by, elementId);

    return element;
  }