Esempio n. 1
0
 /**
  * Revert highlighted elements to original style values
  */
 private function revertHighlighting()
 {
     if (isset($this->highlightingRevertData)) {
         $this->driver->executeScript($this->highlightingRevertData['script'], $this->highlightingRevertData['args']);
         $this->highlightingRevertData = null;
     }
 }
Esempio n. 2
0
 public function run()
 {
     if ($this->remoteWebDriver === null) {
         $this->remoteWebDriver = RemoteWebDriver::create('http://127.0.0.1:8910', DesiredCapabilities::phantomjs());
     }
     $script = '';
     $script .= file_get_contents(__DIR__ . '/js/jquery-2.2.2.min.js');
     $script .= "\n\n";
     $script .= file_get_contents(__DIR__ . '/js/frontendscraper.js');
     $script .= "\n\n";
     while ($job = $this->jobBuffer->getJob()) {
         $status = $this->createInitStatus($job);
         $this->remoteWebDriver->get($job->url);
         $inject = $script;
         $inject .= file_get_contents($this->jobScriptDir . '/' . $job->script);
         $inject .= "\n\n return phantomScraper.getResult();";
         $res = $this->remoteWebDriver->executeScript($inject);
         $this->addJobs($res['jobs']);
         $this->addData($res['data']);
         $this->updateStatus($status);
     }
 }
Esempio n. 3
0
 /**
  * Executes custom JavaScript.
  *
  * This example uses jQuery to get a value and assigns that value to a PHP variable:
  *
  * ```php
  * <?php
  * $myVar = $I->executeJS('return $("#myField").val()');
  * ?>
  * ```
  *
  * @param $script
  * @return mixed
  */
 public function executeJS($script)
 {
     return $this->webDriver->executeScript($script);
 }
Esempio n. 4
0
 /**
  * Move to the middle of the given element matched by the given locator.
  * Extra shift, calculated from the top-left corner of the element, can be set by passing $offsetX and $offsetY parameters.
  *
  * ``` php
  * <?php
  * $I->scrollTo(['css' => '.checkout'], 20, 50);
  * ?>
  * ```
  *
  * @param $selector
  * @param int $offsetX
  * @param int $offsetY
  */
 public function scrollTo($selector, $offsetX = null, $offsetY = null)
 {
     $el = $this->matchFirstOrFail($this->webDriver, $selector);
     $x = $el->getLocation()->getX() + $offsetX;
     $y = $el->getLocation()->getY() + $offsetY;
     $this->webDriver->executeScript("window.scrollTo({$x}, {$y})");
 }