-1

File issueerror on line 3current codeerror for line 3I would like to seek help if there is a possible way / code to capture a screenshot under Krypton platform that uses JAVA selenium. I'm having trouble in terms of it's standardization. Thanks!

var driver = new ChromeDriver()
driver.get("https://login.bws.birst.com/login.html/")
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"))
Mads Cruz
  • 29
  • 6
  • Can you update the question with the exact problem you are facing in terms of _standardization_ to help us what's going wrong? – undetected Selenium Jan 04 '19 at 06:58
  • I don't have any code segment for screenshot right now but i have reference using selenium Java but when using it in krypton, it does not work – Mads Cruz Jan 04 '19 at 07:18
  • That's the reason I am not sure if I can point you to an existing discussion or you require all together a different new answer. Your code trials and error would have helped us to some extent. – undetected Selenium Jan 04 '19 at 07:20
  • So where are you stuck exactly? – undetected Selenium Jan 04 '19 at 07:22
  • all the objects are not working, i would like to ask if what should be the proper way when implementing screenshot when using krypton as a platform – Mads Cruz Jan 04 '19 at 07:23
  • A lot of the contributors may not have access to systems with krypton as a platform and in that case some sample lines of settings/code/error might have helped. – undetected Selenium Jan 04 '19 at 07:28
  • hello i have update the post with pics hopefully you can see it further more ive attached my current code and the lines for 2 and 3 that ahs error – Mads Cruz Jan 04 '19 at 08:44

1 Answers1

0

As per the screenshots there seems to be some discrepency with the imports/Classes. Further to keep things simpler create destination folder within the Project Scope e.g. the Screenshots directory below:

screenshot_folder

To capture a screenshot using Java you can use the following solution:

  • Code Block:

    package screenShot;
    
    import java.io.File;
    import java.io.IOException;
    
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    public class takesScreenshot {
    
        public static void main(String[] args) throws IOException {
    
            System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            options.addArguments("disable-infobars");
            options.addArguments("--disable-extensions"); 
            WebDriver driver =  new ChromeDriver(options);
            driver.get("https://login.bws.birst.com/login.html/");
            new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains("Birst"));
            File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(scrFile, new File(".\\Screenshots\\Mads_Cruz_screenshot.png"));
        }
    }
    
  • Captured Image:

Mads_Cruz_screenshot

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • i'd tried implementing that on my code removing the driver part since i have my own set up. now im having issue on "File scrFile" part but i have my import library for that i don't why it does not work – Mads Cruz Jan 07 '19 at 03:09
  • please see the latest photo attached. i have import java.io.File; idk why it's still not working – Mads Cruz Jan 07 '19 at 03:17