private function captcha() { $path = \Yii::getAlias('@runtime/tmp') . '/' . time() . '_' . rand() . '.png'; $this->driver->takeScreenshot($path); $coordinates = $this->driver->findElement(WebDriverBy::tagName('img'))->getCoordinates()->onPage(); if (Image::crop($path, $coordinates->getX(), $coordinates->getY(), 130, 50)) { if (\Yii::$app->get('captcha')->run($path)) { $this->driver->findElement(WebDriverBy::xpath('//input[@name=\'captcha_key\']'))->click(); $this->driver->findElement(WebDriverBy::xpath('//input[@name=\'captcha_key\']'))->sendKeys(\Yii::$app->get('captcha')->result()); } } else { throw new Exception('Проблема при обрезании картинки'); } }
private function captcha() { $path = \Yii::getAlias('@runtime/tmp') . '/' . time() . '_' . rand() . '.png'; $this->driver->takeScreenshot($path); $coordinates = $this->driver->findElement(WebDriverBy::cssSelector('.captchaImage'))->getCoordinates()->onPage(); if (Image::crop($path, $coordinates->getX(), $coordinates->getY(), 300, 60)) { if (\Yii::$app->get('captcha')->run($path)) { $this->driver->findElement(WebDriverBy::id('CaptchaInput'))->click(); $this->driver->findElement(WebDriverBy::id('CaptchaInput'))->sendKeys(\Yii::$app->get('captcha')->result()); $this->driver->findElement(WebDriverBy::name('submit_captcha'))->click(); sleep(2); } } else { throw new Exception('Проблема при обрезании картинки'); } }