public bool Equals(HtmlElement rhs)
 {
     if (rhs == null) return false;
     if (!string.IsNullOrEmpty(Id)) if (!Id.Equals(rhs.Id)) return false;
     if (!string.IsNullOrEmpty(Name)) if (!Name.Equals(rhs.Name)) return false;
     if (!string.IsNullOrEmpty(OnClick)) if (!OnClick.Equals(rhs.OnClick)) return false;
     if (!string.IsNullOrEmpty(TagName)) if (!TagName.Equals(rhs.TagName)) return false;
     return true;
 }
		public void SetElementProperty(HtmlElement element, string propertyName)
		{
			startSWATFixtureIfNotInOne();
            string newValue = string.Empty;
            if (element.TagName == "TEXTAREA")
            {
                newValue = element.InnerHtml;
            }
            else
            {
                newValue = element.GetType().InvokeMember(propertyName, System.Reflection.BindingFlags.GetProperty, null, element, new object[] { }).ToString();
            }
			_sb.AppendFormat("|SetElementAttribute|{0}|", !string.IsNullOrEmpty(element.Id) ? "id" : "name");
			_sb.AppendFormat("{0}", !string.IsNullOrEmpty(element.Id) ? element.Id : element.Name);
			_sb.AppendFormat("|{0}|{1}|{2}|", propertyName, newValue, element.TagName);
			writeCommand(getStringBuilderValueAndReset());
		}
		public void AssertElement(AssertionType type, String assertion, HtmlElement element)
		{
			startSWATFixtureIfNotInOne();
			//_assertion = "|AssertElementExists|expression|" + assertionBox.Text + "|" + _srcElement.tagName + "|";
			switch (type)
			{
				case AssertionType.ElementExists:
					_sb.Append("|AssertElementExists|Expression|");
					break;
				case AssertionType.ElementDoesNotExist:
					_sb.Append("|AssertElementDoesNotExist|Expression|");
					break;
			}
            //assertion = replaceSpecialCharacters(assertion);
			_sb.Append(assertion + "|" + element.TagName + "|");
			writeCommand(getStringBuilderValueAndReset());
		}
		protected string getFindExpression(HtmlElement element)
		{

			StringBuilder findExpression = new StringBuilder();

			if (!string.IsNullOrEmpty(element.Id))
			{
				findExpression.AppendFormat("id:{0}", element.Id);
			}
			else if (!string.IsNullOrEmpty(element.Name))
			{
				findExpression.AppendFormat("name:{0}", element.Name);
			}
			else if (!string.IsNullOrEmpty(element.InnerHtml))
			{
				findExpression.AppendFormat("innerHtml:{0}", element.InnerHtml);
				if (!string.IsNullOrEmpty(element.Href))
				{
					findExpression.AppendFormat(";href:{0}", element.Href);
				}
			}
			else if (!string.IsNullOrEmpty(element.Href))
			{
				findExpression.AppendFormat("href:{0}", element.Href);
			}
			else if (!string.IsNullOrEmpty(element.Value))
			{
				findExpression.AppendFormat("value:{0}", element.Value);
			}

			if (!string.IsNullOrEmpty(element.OnClick))
			{
				findExpression.AppendFormat(";onclick:{0}", element.OnClick);
			}

			return findExpression.ToString();

			//String temp = "";
			//if (!string.IsNullOrEmpty(element.id))
			//{
			//    temp += string.Format("id:{0};", element.id);
			//}
			//if (!string.IsNullOrEmpty(element.name))
			//{
			//    temp += string.Format("name:{0};", element.name);
			//}
			//if (string.IsNullOrEmpty(temp))
			//{
			//    if (!string.IsNullOrEmpty(element.innerHtml))
			//    {
			//        temp += string.Format("innerHtml:{0};", element.innerHtml);
			//    }
			//    if (!string.IsNullOrEmpty(element.href))
			//    {
			//        temp += string.Format("href:{0};", element.href);
			//    }
			//    if (!string.IsNullOrEmpty(element.value))
			//    {
			//        temp += string.Format("value:{0};", element.value);
			//    }
			//}
			//return string.IsNullOrEmpty(temp) ? "" : temp.Substring(0,temp.Length-1);
		}
		/*public void SubmitElement(HtmlElement element)
		{
			 startSWATFixtureIfNotInOne();

			 _sb.Append("|StimulateElement|Expression|");

			 _sb.Append(getFindExpression(element));

			 _sb.Append("|onsubmit|");

			 if (!string.IsNullOrEmpty(element.tagName))
			 {
				  _sb.AppendFormat("{0}|", element.tagName);
			 }

			 writeCommand(getStringBuilderValueAndReset());
		}

		public void ClickElement(HtmlElement element)
		{
			 //StringBuilder sb = new StringBuilder();
			 startSWATFixtureIfNotInOne();

			 _sb.Append("|StimulateElement|Expression|");

			 _sb.Append(getFindExpression(element));

			 _sb.Append("|onclick|");

			 if (!string.IsNullOrEmpty(element.tagName))
			 {
				  _sb.AppendFormat("{0}|", element.tagName);
			 }

			 writeCommand(getStringBuilderValueAndReset());

			 //			if(!string.IsNullOrEmpty(sb.ToString()))
			 //				writeCommand(sb.ToString());
			 //OnFinishedWritingBatchOfCommands(null, new EventArgs());
		}*/

		public void StimulateElement(HtmlElement element, string eventName)
		{
			//StringBuilder sb = new StringBuilder();
			startSWATFixtureIfNotInOne();

			_sb.Append("|StimulateElement|Expression|");

			_sb.Append(getFindExpression(element));

			_sb.Append(string.Format("|{0}|", eventName));

			if (!string.IsNullOrEmpty(element.TagName))
			{
				_sb.AppendFormat("{0}|", element.TagName);
			}

			//double click occured, remove upto 2 previous click events
			if (eventName.Equals("ondblclick"))
			{
				if (((String)commandList[commandList.Count - 1]).Contains("|onclick|"))
				{
					commandList.RemoveAt(commandList.Count - 1);
				}
				if (((String)commandList[commandList.Count - 1]).Contains("|onclick|"))
				{
					commandList.RemoveAt(commandList.Count - 1);
				}
			}
            if (element.TagName == "TEXTAREA" || element.TagName == "HTML") //Clicks on a textarea or in an html element should not be recorded.
            {
                getStringBuilderValueAndReset();
            }
            else
            {
                writeCommand(getStringBuilderValueAndReset());
            }
          

			//			if(!string.IsNullOrEmpty(sb.ToString()))
			//				writeCommand(sb.ToString());
			//OnFinishedWritingBatchOfCommands(null, new EventArgs());
		}