Skip to content
Browse files

added checkbox wrapper to find checkbox with name and value

  • Loading branch information...
1 parent 6259be4 commit a5bc5b51d25daa790858e2aa75db3150d68590be @shashankshetty shashankshetty committed Jun 14, 2013
Showing with 49 additions and 4 deletions.
  1. +49 −4 src/FluentBrowserAutomation/BrowserContext.cs
View
53 src/FluentBrowserAutomation/BrowserContext.cs
@@ -21,6 +21,8 @@ public interface IBrowserContext
IEnumerable<ButtonWrapper> Buttons();
CheckBoxWrapper CheckBoxWithId([NotNull] string id);
CheckBoxWrapper CheckBoxWithLabel([NotNull] string id);
+ CheckBoxWrapper CheckBoxWithIdAndValue([NotNull] string id, [NotNull] string value);
+ CheckBoxWrapper CheckBoxWithNameAndValue([NotNull] string name, [NotNull] string value);
IEnumerable<CheckBoxWrapper> CheckBoxes();
IEnumerable<CheckBoxWrapper> CheckBoxesWithName([NotNull] string name);
void CloseBrowser();
@@ -113,6 +115,20 @@ public CheckBoxWrapper CheckBoxWithId(string id)
return new CheckBoxWrapper(checkBox, String.Format(howFound, id), this);
}
+ public CheckBoxWrapper CheckBoxWithNameAndValue(string name, string value)
+ {
+ const string howFound = "checkbox with name '{0}'";
+ var checkBox = TryGetElementByNameAndInputTypeAndValue(name, "checkbox", value);
+ return new CheckBoxWrapper(checkBox, String.Format(howFound, name), this);
+ }
+
+ public CheckBoxWrapper CheckBoxWithIdAndValue(string id, string value)
+ {
+ const string howFound = "checkbox with id '{0}'";
+ var checkBox = TryGetElementByIdAndInputTypeAndValue(id, "checkbox", value);
+ return new CheckBoxWrapper(checkBox, String.Format(howFound, id), this);
+ }
+
public CheckBoxWrapper CheckBoxWithLabel(string label)
{
var input = InputWithLabel(label);
@@ -271,10 +287,25 @@ public LinkWrapper LinkWithText(string text)
string htmlEscapedText = HttpUtility.HtmlEncode(text);
const string howFound = "link with visible text '{0}'";
var link = Browser.FindElements(By.LinkText(text)).FirstOrDefault() ?? GetElementsByTagType("a").FirstOrDefault(x =>
- {
- var attribute = x.GetAttribute("innerHTML");
- return attribute == htmlEscapedText || attribute == text || attribute.Trim() == text;
- });
+ {
+ string
+ attribute
+ =
+ x
+ .
+ GetAttribute
+ ("innerHTML");
+ return
+ attribute ==
+ htmlEscapedText ||
+ attribute ==
+ text ||
+ attribute
+ .
+ Trim
+ () ==
+ text;
+ });
return new LinkWrapper(link, String.Format(howFound, text), this);
}
@@ -468,6 +499,20 @@ private IWebElement TryGetElementByIdAndInputType(string id, string type)
return Browser.FindElements(By.Id(id)).FirstOrDefault(x => x.GetAttribute("type") == type);
}
+ private IWebElement TryGetElementByIdAndInputTypeAndValue(string id, string type, string value)
+ {
+ return
+ Browser.FindElements(By.Id(id)).FirstOrDefault(
+ x => x.GetAttribute("type") == type && x.GetAttribute("value") == value);
+ }
+
+ private IWebElement TryGetElementByNameAndInputTypeAndValue(string name, string type, string value)
+ {
+ return
+ Browser.FindElements(By.Name(name)).FirstOrDefault(
+ x => x.GetAttribute("type") == type && x.GetAttribute("value") == value);
+ }
+
private IWebElement TryGetElementByIdAndTagType(string id, string tag)
{
return Browser.FindElements(By.Id(id)).FirstOrDefault(x => x.TagName == tag);

0 comments on commit a5bc5b5

Please sign in to comment.
Something went wrong with that request. Please try again.