自動テストツール Selenium2 4/5

wait処理

wait.Until

//指定のタイトルになるまで10秒待つ。
//ならなかったらNUnitでエラー表示
WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 10));
wait.Until(ExpectedConditions.TitleIs(“TEST”));

//指定の要素があるかチェック
wait.Until(ExpectedConditions.ElementExists(By.Id(“myText”)));

//指定の要素が可視かチェック
wait.Until(ExpectedConditions.ElementIsVisible(By.Id(“myText”)));

メソッド

Clear()

//要素のクリア
IWebElement element = driver.FindElement(By.Id(“myText”));
element.Clear();
//こういう書き方も可(メソッドチェーン)
driver.FindElement(By.Name(“myText”)).Clear();

SendKeys()

//要素への入力(追記)
element.SendKeys(“yahoo”);
//こういう書き方も可(メソッドチェーン)
driver.FindElement(By.Name(“myText”)).SendKeys(“yahoo”);

Submit()

element.Submit();

Click()

//ボタン・リンクのクリック
driver.FindElement(By.Name(“btnK”)).Click();
driver.FindElement(By.LinkText(“Selenium – Web Browser Automation”)).Click();

GetAttribute()

//指定要素のvalue属性値取得
Assert.AreEqual(“aaayahoo”, element.GetAttribute(“value”));

GetCssValue()

GetScreenshot()

//スクリーンショットを保存(bin内)
Screenshot shot = ((ITakesScreenshot)driver).GetScreenshot();
byte[] screenshotAsByteArray = shot.AsByteArray;
shot.SaveAsFile(“firefox.png”, ImageFormat.Png);

プロパティ

Displayed

Enabled

Location

Selected

CheckBox、Select等

Size

TagName

Text

タグ間テキスト