seleniumを使ってC#でGoogle Chromeの自動操作をする
3817 ワード
やりたいこと
1.Google Chromeでhttps://www.google.co.jp/を開く
2.テキストボックスに"Selenium"を入力
3.「Google 検索」ボタンをクリック
環境
- Windows 7
- Google Chrome 77
- Visual Studio Community 2019
準備
1.C#のコンソールアプリでプロジェクトを作成
2.NuGetパッケージ管理にて以下をインストール
- Selenium.WebDriver
- Selenium.WebDriver.ChromeDriver
ソース
Program.cs
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace SeleniumChromeSample
{
class Program
{
/// <summary>
/// SeleniumでIEを自動操作するサンプル
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
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();
}
}
}
参考
Author And Source
この問題について(seleniumを使ってC#でGoogle Chromeの自動操作をする), 我々は、より多くの情報をここで見つけました https://qiita.com/natuki33/items/c0947c31fc733b4e39ef著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .