4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

seleniumを使ってC#でIEの自動操作をする

Last updated at Posted at 2019-09-08

#やりたいこと
1.IEでhttps://www.google.co.jp/を開く
2.テキストボックスに"Selenium"を入力
3.「Google 検索」ボタンをクリック
##環境

  • Windows 7
  • Internet Explorer 11
  • Visual Studio Community 2019

##準備
1.C#のコンソールアプリでプロジェクトを作成
2.NuGetパッケージ管理にて以下をインストール

  • Selenium.WebDriver
  • Selenium.WebDriver.IEDriver

##ソース

Program.cs
using OpenQA.Selenium;
using OpenQA.Selenium.IE;

namespace SeleniumIESample
{
    class Program
    {
        /// <summary>
        /// SeleniumでIEを自動操作するサンプル
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            IWebDriver driver = new InternetExplorerDriver();
            IWebElement textbox;
            IWebElement findbuttom;

            //Webページを開く
            driver.Navigate().GoToUrl("https://www.google.co.jp/");

            //検索ボックス
            textbox = driver.FindElement(By.Name("q"));
            //検索ボックスに検索ワードを入力
            textbox.SendKeys("Selenium");

            //検索ボタン
            findbuttom = driver.FindElement(By.Name("btnK"));
            //検索ボタンをクリック
            findbuttom.Click();

        }
    }
}

##参考
Selenium - Web Browser Automation

4
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?