使用 selenium 和 Nunit 在 C# 中断言实际值

Asserting an actual value in C# using selenium and Nunit

嗨,我正在使用 Nunit 和 Selenium 网络驱动程序。我以前在同一上下文中使用过 Java 我正在努力解决这行代码。

`string actualvalue = IWebElement searchInput =` `driver.FindElement(By.Id("sb_form_q"));`

这是剩下的。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using NUnit.Framework;

namespace SeleniumTests1
{
    [TestFixture]
    class SeleniumTest
    {
        [Test]
        public void Main(string[] args)
        {

            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.bing.com/");
            driver.Manage().Window.Maximize();

            string actualvalue = IWebElement searchInput = driver.FindElement(By.Id("sb_form_q"));
            searchInput.SendKeys("Hello World");
            searchInput.SendKeys(Keys.Enter);

            Assert.AreEqual(actualvalue, "Hello World");
            driver.Close();
        }
    }
}

这对我有用:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace ConsoleApplication1
{
    public static class SeleniumTest
    {
        public static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.bing.com/");
            driver.Manage().Window.Maximize();

            IWebElement searchInput = driver.FindElement(By.Id("sb_form_q"));
            searchInput.SendKeys("Hello World");
            searchInput.SendKeys(Keys.Enter);

            searchInput = driver.FindElement(By.Id("sb_form_q"));
            string actualvalue = searchInput.GetAttribute("value");

            Assert.AreEqual(actualvalue, "Hello World");
            driver.Close();
        }
    }
}