私があなたの言うことを正しく理解していれば、Web ブラウザーで URL を開いて、通常のユーザーと同じようにサイトと対話したいと思うでしょう。そのようなタスクについては、 Seleniumを参照することをお勧めします。通常、回帰テストの自動化ツールとして使用されますが、ブラウザー自動化ツールとしての使用を止めることはできません。
Selenium には詳細なドキュメントと大きなコミュニティがあります。ほとんどの場合、 nugetから入手できるSelenium WebDriverを使用したいと思うでしょう。
以下は、典型的な Selenium の "スクリプト" の小さな例です (ドキュメントからそのまま引用):
// Create a new instance of the Firefox driver.
// Notice that the remainder of the code relies on the interface,
// not the implementation.
// Further note that other drivers (InternetExplorerDriver,
// ChromeDriver, etc.) will require further configuration
// before this example will work. See the wiki pages for the
// individual drivers at http://code.google.com/p/selenium/wiki
// for further information.
IWebDriver driver = new FirefoxDriver();
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl("http://www.google.com/");
// Find the text input element by its name
IWebElement query = driver.FindElement(By.Name("q"));
// Enter something to search for
query.SendKeys("Cheese");
// Now submit the form. WebDriver will find the form for us from the element
query.Submit();
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
// Should see: "Cheese - Google Search"
System.Console.WriteLine("Page title is: " + driver.Title);
//Close the browser
driver.Quit();
個人的には、ユーザー アクション (登録、ログイン、フォームへの入力、グリッドでの選択、グリッドのフィルターなど) の観点からスクリプトを考えて整理することをお勧めします。これにより、乱雑なハードコーディングされたコード チャンクの代わりに、スクリプトに適切な形と読みやすさが与えられます。この場合のスクリプトは次のようになります。
// Fill username and password
// Click on button "login"
// Wait until page got loaded
LoginAs("johndoe@domain.com", "johndoepasswd");
// Follow link in navigation menu
GotoPage(Pages.Reports);
// Fill inputs to reflect year-to-date filter
// Click on filter button
// Wait until page refreshes
ReportsView.FilterBy(ReportsView.Filters.YTD(2012));
// Output value of Total row from grid
Console.WriteLine(ReportsView.Grid.Total);