How can I take a screenshot with Selenium WebDriver?

后端 未结 30 2633
不知归路
不知归路 2020-11-21 07:48

Is it possible to take a screenshot using Selenium WebDriver?

(Note: Not Selenium Remote Control)

30条回答
  •  误落风尘
    2020-11-21 08:28

    PHP

    public function takescreenshot($event)
      {
        $errorFolder = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "ErrorScreenshot";
    
        if(!file_exists($errorFolder)){
          mkdir($errorFolder);
        }
    
        if (4 === $event->getResult()) {
          $driver = $this->getSession()->getDriver();
          $screenshot = $driver->getWebDriverSession()->screenshot();
          file_put_contents($errorFolder . DIRECTORY_SEPARATOR . 'Error_' .  time() . '.png', base64_decode($screenshot));
        }
      }
    

提交回复
热议问题