LoginSignup
3
5

More than 1 year has passed since last update.

C# Seleniumでスクリーンショット --メモ--

Last updated at Posted at 2021-07-08

googleで"Selenium C#"を検索。 結果をスクリーンショット。
画像はexeと同じ場所に保存。

※ 例外処理はしていません。

using System;
using System.IO;
using System.Reflection;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            IWebDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));

            driver.Navigate().GoToUrl(@"https://www.google.co.jp/");

            IWebElement qbox = driver.FindElement(By.Name("q"));

            qbox.SendKeys("Selenium C#");

            qbox.Submit();

            driver.Manage().Window.FullScreen();

            Screenshot screenshot = (driver as ITakesScreenshot).GetScreenshot();
            screenshot.SaveAsFile("SeleniumとC#の検索結果.png", ScreenshotImageFormat.Png);

            Console.ReadKey();
            driver.Quit();
        }
    }
}


3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5