2016-02-16 45 views
0

我想截取網頁截圖。 我寫了2行代碼,但我得到「TakesScreenshot無法解析爲類型」。請在下面找到我的代碼。查找文件f1,scrFile或scrFile1。我嘗試了所有3仍然錯誤持續。TakesScreenshot無法解析爲Selenium中的類型WebDriver

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")); 



    } 

} 

回答

0

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

+0

我仍然得到同樣的錯誤。 「屏幕截圖無法解析爲類型」 –

+0

@MohammedSajjad我編輯了我的答案,用'TakesScreenshot'使用舊代碼並添加'import org.openqa.selenium.TakesScreenshot;' – Guy