How can I take a screenshot with Selenium WebDriver?

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

    Jython

    import org.openqa.selenium.OutputType as OutputType
    import org.apache.commons.io.FileUtils as FileUtils
    import java.io.File as File
    import org.openqa.selenium.firefox.FirefoxDriver as FirefoxDriver
    
    self.driver = FirefoxDriver()
    tempfile = self.driver.getScreenshotAs(OutputType.FILE)
    FileUtils.copyFile(tempfile, File("C:\\screenshot.png"))
    

提交回复
热议问题