0

私は WebDriver を初めて使用し、このコードを C# Visual Studio (以下のコード スニペット) で記述しています。IsElementPresent を使用して、ホーム ページにテキスト フィールドが存在するかどうかを確認しています。The name IsElementPresent does not exist in the current context というエラーが表示されます。私は何を間違っていますか?

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading;
using System.Linq;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;

namespace Homepage_check2
{
    [TestFixture]
    public class Driver
    {
        IWebDriver driver;

        [SetUp]
        public void Setup()
        {
            // Create a new instance of the Firefox driver
            driver = new FirefoxDriver();
        }

        [TearDown]
        public void Teardown()
        {
            driver.Quit();
        }

        [Test]
        public void homepage()
        {
            //Navigate to the site
            driver.Navigate().GoToUrl("http://www.milkround.com");

           Assert.IsTrue(IsElementPresent(By.Id("ctl00_uxToolbar_uxQueryTextBoxToolbar")));

        }
        catch
        {
            //verificationErrors.Append(e.Message);
        }

        }
    }
}
4

1 に答える 1

1

「IsElementPresent」はどこから来たのですか? WebDriverで使用されているのを見たことがありません。

WebDriver では、findElement メソッドを try キャッチでラップする必要があります。

例えば

Boolean elementDisplayed;

try {

WebElement element = driver.findElement(By.Id("ctl00_uxToolbar_uxQueryTextBoxToolbar"));
elementDisplayed = element.displayed; 

}
catch (NoSuchElementException e) {
elementDisplayed = false;
}

明らかに、これをある種のヘルパー メソッドでラップして、おそらく WebDriver クラスに追加することができます。

それはあなたに任せますが、これが一般的な考え方です

于 2013-08-28T15:35:08.783 に答える