How can I take a screenshot with Selenium WebDriver?

后端 未结 30 2584
不知归路
不知归路 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:23

    JavaScript (Selenium-Webdriver)

    driver.takeScreenshot().then(function(data){
       var base64Data = data.replace(/^data:image\/png;base64,/,"")
       fs.writeFile("out.png", base64Data, 'base64', function(err) {
            if(err) console.log(err);
       });
    });
    

提交回复
热议问题