首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将TakesScreenshot解析为Selenium WebDriver中的类型

无法将TakesScreenshot解析为Selenium WebDriver中的类型
EN

Stack Overflow用户
提问于 2016-02-16 21:23:21
回答 1查看 3.4K关注 0票数 0

我想要为一个网页截图。我写了两行代码,但是我得到了"TakesScreenshot不能被解析成一个类型“。请找到我的代码下面。查找文件f1、scrFile或scrFile1。我尝试了所有3个仍然错误仍然存在。

代码语言:javascript
复制
import java.io.File;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Radio {

    public static void main(String[] args) {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://echoecho.com/htmlforms10.htm");

        File f1 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(f1, "E:\\Pessoal\\QTPSelenium\\Screenshot1.jpg");

        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, new File("File Location\\File Name"),true);

        File scrFile1 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        // Now you can do whatever you need to do with it, for example copy somewhere
        FileUtils.copyFile(scrFile1, new File("c:\\tmp\\screenshot.png"));

        driver.manage().window().maximize();
        List<WebElement> allRadios= driver.findElements(By.name("group1"));
        System.out.println("Total -->"+allRadios.size());

        System.out.println("Before");
        System.out.println(allRadios.get(0).getAttribute("checked"));
        System.out.println(allRadios.get(1).getAttribute("checked"));       
        System.out.println(allRadios.get(2).getAttribute("checked"));
        allRadios.get(0).click();
        System.out.println("After");
        System.out.println(allRadios.get(0).getAttribute("checked"));
        System.out.println(allRadios.get(1).getAttribute("checked"));       
        System.out.println(allRadios.get(2).getAttribute("checked"));



    }

}
EN

回答 1

Stack Overflow用户

发布于 2016-02-16 21:32:51

您需要使用import org.openqa.selenium.TakesScreenshot;

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35433831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档