I have a problem with selenium in C#. Below is my code but I have still the same error: cannot convert from 'System.Drawing.Imaging.ImageFormat' to 'OpenQA.Selenium.ScreenshotImageFormat'
How can I fix it? Any ideas?
using System;
using System.Drawing.Imaging;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Drawing;
namespace Test
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("xx://xx.xx.xx");
driver.FindElement(By.Id("xx")).SendKeys("xxx");
driver.FindElement(By.Id("xx")).SendKeys("xxx");
driver.FindElement(By.Id("xx")).Click();
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
ss.SaveAsFile(@"C:\\test.Png", System.Drawing.Imaging.ImageFormat.Png);
Console.Read();
Console.WriteLine("xxx");
}
}
}
Instead of System.Drawing.Imaging.ImageFormat.Png
as the 2nd param of your SaveAsFile, you need to use OpenQA.Selenium.ScreenshotImageFormat.[something here]
That enum probably has it's own PNG format.
The error was persistent, saying:
System.Drawing.Imaging.ImageFormat is not supported. Please change format.
Then I changed code from:
ScreenShot.SaveAsFile(FileName.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);
To:
ScreenShot.SaveAsFile(FileName.ToString(), ScreenshotImageFormat.Jpeg);
And it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With