'Java-Selenium- Unable to find an exact match for CDP version 98, so returning the closest version found: 97

I have created a maven project for taking a screenshot from the webpage URL which I have given in my code. I am using chrome driver version 98 and selenium version 4.1.2. I'm getting a warning message with the CDP versions when running my code. Here is my code. TakeScreenshot.java

public class Takescreenshot
{
    private static final File SrcnewFile = null;

    public static void main(String[] args) throws Exception
    {
        WebDriver driver ;
        WebDriverManager.chromedriver().clearCache();
        //System.setProperty("webdriver.chrome.driver","C:\drivers/chromedriver.exe");
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
        driver.get("https://www.amazon.in/");
        TakesScreenshot scrShot =((TakesScreenshot)driver);
        File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
        if(null!=null) 
        {
            File DestFile=new File("c:test/test1.png");
            FileUtils.copyFile(SrcFile, DestFile);
            FileUtils.getFile(SrcnewFile, ("c://test1.png"));
             driver.quit();  
        }
    }
}

When I try to run my program the following error shows up.

    Starting ChromeDriver 98.0.4758.80 (7f0488e8ba0d8e019187c6325a16c29d9b7f4989-refs/branch-heads/4758@{#972}) on port 58811
Only local connections are allowed.

    Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
    ChromeDriver was started successfully.
    Feb 15, 2022 12:53:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: W3C
    Feb 15, 2022 12:53:33 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
    WARNING: Unable to find an exact match for CDP version 98, so returning the closest version found: 97
    Feb 15, 2022 12:53:33 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
    INFO: Found CDP implementation for version 98 of 97

I'm using Maven. My pom.xml file looks like this

 <dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>31.0.1-jre</version>
</dependency>
    <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.7</version>
</dependency>
    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.1.2</version>
</dependency>   
<dependency>
  <groupId>io.github.bonigarcia</groupId>
  <artifactId>webdrivermanager</artifactId>
  <version>3.6.2</version>
</dependency>

When I run the java program the chrome browser will open and the page is loaded, but the screenshot of the page is not generating and couldn't be saved in the local machine. Could anyone please help me to resolve it?



Solution 1:[1]

Please using following code:

    TakesScreenshot scrShot =((TakesScreenshot)driver);
    File srcFile = scrShot.getScreenshotAs(OutputType.FILE);
    if(srcFile != null)
    {
        File saveFileName = new File("test1.png");
        FileHandler.copy(srcFile, saveFileName);
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anh Tester