protected function waitForElement($type, $value, $timeout)
    {
        if (!in_array($type, $this->waitForTypes)) {
            throw new \Exception('Invalid wait for element type to wait for on the page');
        }

        $webdriver = $this;
        $this->waitUntil(function () use ($type, $value, $webdriver) {
            $function = 'by'.$type;

            try {
                $webdriver->$function($value);

                return true;
            } catch (\Exception $e) {
                return; // haven't found the element yet
            }
        }, $timeout);
    }