2016-03-08 42 views
0

HI我正在使用Nunit和Selenium网络驱动程序。我以前在相同的上下文中使用过Java,我正在努力解决这一行代码。在C#中使用硒和Nunit声明实际值

`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(); 
     } 
    } 
} 
+0

嗯,是的,这句法无效......什么是你想达到什么目的?也许你只需要两个语句,一个声明并初始化'searchInput',另一个声明并初始化'actualValue'? –

+0

我对C#相当陌生,所以我正在基于我的Java知识工作。在这种情况下,我想查看我输入的Hello世界是否实际上已经在搜索之后输入搜索。 – Peter

+0

这在Java语言中也是语法无效的......在C#和Java之间声明和初始化变量的基础知识非常类似。 –

回答

0

这个工作对我来说:

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(); 
     } 
    } 
}