本文整理汇总了C#中Browser.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Browser.Select方法的具体用法?C# Browser.Select怎么用?C# Browser.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Browser
的用法示例。
在下文中一共展示了Browser.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SearchingAnInputElementBySeveralSelectingMethods
public void SearchingAnInputElementBySeveralSelectingMethods()
{
Browser b = new Browser();
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.SimpleForm.htm"));
var colorBox = b.Find("colorBox"); // find by id
Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with ID colorBox");
colorBox = b.Find("input", new {name="colorBox", type="color"}); // find by attributes
Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with name colorBox and type color");
colorBox = b.Find("input", new { name = "colorBox", type = "Color" }); // find by attributes
Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with name colorBox and type color");
colorBox = b.Find("input", new { name = "colorBox", type = "Colors" }); // find by attributes
Assert.That(colorBox.Exists == false, "There should be no element with name colorBox and type Colors");
colorBox = b.Find(ElementType.TextField, new { name = "colorBox", type = "Color" }); // find by attributes
Assert.That(colorBox.Count() == 0, "Input elements with types other than text, password and hidden should not be found");
colorBox = b.Find("input", FindBy.Name, "colorBox"); // find by FindBy
Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with name colorBox");
colorBox = b.Select("input[name=colorBox]"); // find by Css selector
Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with name colorBox");
colorBox = b.Select("input[type=color]"); // find by Css selector
Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with type color");
colorBox = b.Select("input[type=Color]"); // find by Css selector
Assert.That(colorBox.Count() == 0, "There should be no element for the expression input[type=Color] (CSS is case sensitive)");
var clickLink = b.Select(".clickLink"); // find by Css selector
Assert.That(clickLink.Count() == 1, "There should be one element for the expression .clickLink");
}
示例2: Forms_Disabled_and_ReadOnly
public void Forms_Disabled_and_ReadOnly()
{
Browser b = new Browser();
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.HTML5Elements.htm"));
var textarea = b.Find("readonlytextarea");
textarea.Value = "some value";
Assert.IsTrue(textarea.Value == "readme textarea");
Assert.IsTrue(textarea.ReadOnly);
Assert.IsFalse(textarea.Disabled);
textarea = b.Find("disabledtextarea");
textarea.Value = "some value";
Assert.IsTrue(textarea.Value == "disableme textarea");
Assert.IsFalse(textarea.ReadOnly);
Assert.IsTrue(textarea.Disabled);
var textinput = b.Find("readonlytext");
textinput.Value = "some value";
Assert.IsTrue(textinput.Value == "readme");
Assert.IsTrue(textinput.ReadOnly);
Assert.IsFalse(textinput.Disabled);
textinput = b.Find("disabledtext");
textinput.Value = "some value";
Assert.IsTrue(textinput.Value == "disableme");
Assert.IsFalse(textinput.ReadOnly);
Assert.IsTrue(textinput.Disabled);
var checkbox = b.Find("disabledcheck");
Assert.IsTrue(checkbox.Disabled);
var radio = b.Find("disabledradio");
Assert.IsTrue(radio.Disabled);
HtmlResult disabledSubmit = b.Find("ds");
Assert.IsTrue(disabledSubmit.Disabled);
ClickResult clickResult = disabledSubmit.Click();
Assert.IsTrue(clickResult == ClickResult.SucceededNoOp);
HtmlResult submit = b.Find("es");
Assert.IsFalse(submit.Disabled);
clickResult = submit.Click();
Assert.IsTrue(clickResult == ClickResult.SucceededNavigationComplete);
// Check to make sure the form submitted.
var names = b.Select("td.desc");
var values = b.Select("td.val");
Assert.IsTrue(names.Count() == values.Count());
Assert.IsTrue(values.Where(e => e.Value == "readme textarea").FirstOrDefault() != null);
// Now, validate that the disabled fields were not.
Assert.IsTrue(values.Where(e => e.Value == "disableme textarea").FirstOrDefault() == null);
Assert.IsTrue(values.Where(e => e.Value == "disableme").FirstOrDefault() == null);
Assert.IsTrue(values.Where(e => e.Value == "disabledcheck").FirstOrDefault() == null);
Assert.IsTrue(values.Where(e => e.Value == "disabledradio").FirstOrDefault() == null);
Assert.IsTrue(values.Where(e => e.Value == "disabledselect").FirstOrDefault() == null);
}
示例3: When_Setting_GZip_Encoding_Content_Should_Still_Be_Returned_As_Text
public void When_Setting_GZip_Encoding_Content_Should_Still_Be_Returned_As_Text()
{
Browser b = new Browser();
b.UseGZip = true;
HttpRequestLog lastRequest = null;
b.RequestLogged += (br, l) =>
{
lastRequest = l;
};
b.Navigate("http://www.facebook.com/");
Assert.That(b.Url.Host == "www.facebook.com");
Assert.That(b.Select("Title") != null);
Assert.That(b.Select("Title").Value.IndexOf("Facebook", StringComparison.OrdinalIgnoreCase) > -1);
}
示例4: UsePlusSelector
public void UsePlusSelector()
{
Browser b = new Browser();
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.SimpleForm.htm"));
var inputDirectlyUnderForm = b.Select("div + input");
Assert.That(inputDirectlyUnderForm.Count() == 1); // only one <input> comes directly after a div
}
示例5: HtmlElement_DecodedValue
public void HtmlElement_DecodedValue()
{
Browser b = new Browser();
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.DecodedValue.htm"));
var div = b.Select("div");
Assert.That(div.DecodedValue, Is.EqualTo("£ sign"));
}
示例6: Uploading_A_File_With_Enctype_MultipartMime
public void Uploading_A_File_With_Enctype_MultipartMime()
{
Browser b = new Browser(Helper.GetAllways200RequestMocker());
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.FileUpload.htm"));
HttpRequestLog lastLog = null;
b.RequestLogged += (br, l) =>
{
lastLog = l;
};
var form = b.Select("form");
var file = b.Select("input[name=theFile]");
DirectoryInfo dir = new FileInfo(Assembly.GetCallingAssembly().Location).Directory;
file.Value = dir.GetFiles()[3].FullName;
form.SubmitForm();
Assert.NotNull(lastLog);
Assert.That(lastLog.Method == "POST");
}
示例7: SearchingAnInputElementBySeveralSelectingMethods
public void SearchingAnInputElementBySeveralSelectingMethods()
{
Browser b = new Browser();
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.FileUpload.htm"));
HttpRequestLog lastLog = null;
b.RequestLogged += (br, l) =>
{
lastLog = l;
};
var form = b.Select("form");
var file = b.Select("input[name=theFile]");
DirectoryInfo dir = new FileInfo(Assembly.GetCallingAssembly().Location).Directory;
file.Value = dir.GetFiles()[3].FullName;
form.SubmitForm();
Assert.NotNull(lastLog);
Assert.That(lastLog.Method == "POST");
}
示例8: HtmlElement_DecodedValue_MalformedDocument
public void HtmlElement_DecodedValue_MalformedDocument()
{
Browser b = new Browser();
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.DecodedValue-malformed.htm"));
var div = b.Select("div");
Assert.That(div.ToList()[0].DecodedValue, Is.EqualTo("Blah £ sign üü"));
Assert.That(div.ToList()[1].DecodedValue, Is.EqualTo("£ sign"));
Assert.That(div.ToList()[2].DecodedValue, Is.EqualTo("üü"));
}
示例9: CanLoadHtmlFromFile
public void CanLoadHtmlFromFile()
{
Regex start = new Regex("^([a-z]):\\\\");
var b = new Browser();
var f = new FileInfo(".\\SampleDocs\\movies1.htm");
string uri = start.Replace(f.FullName, "file:///$1/");
uri = uri.Replace("\\", "/");
b.Navigate(uri);
Assert.AreEqual(b.Select("ul#menu>li").Count(), 3, "Not loaded");
}
示例10: CanLoadHtmlFromFile
public void CanLoadHtmlFromFile()
{
var f = new FileInfo(".\\SampleDocs\\movies1.htm");
string uri = string.Format("file:///{0}", f.FullName);
uri = uri.Replace("\\", "/");
var b = new Browser();
b.Navigate(uri);
Assert.AreEqual(b.Select("ul#menu>li").Count(), 3, "Not loaded");
}
示例11: SearchingAnElementBySeveralSelectingMethods
public void SearchingAnElementBySeveralSelectingMethods()
{
Browser b = new Browser();
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.SimpleForm.htm"));
var colorBox = b.Find("first-checkbox"); // find by id
Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with ID first-checkbox");
colorBox = b.Select("*[type=checkbox][checked]");
Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with type checkbox and checked");
}
示例12: CanLoadHtmlFromFilesWithAbsolutePath
public void CanLoadHtmlFromFilesWithAbsolutePath()
{
if (Directory.Exists("C:\\Windows\\Temp"))
{
File.Copy("SampleDocs\\movies1.htm", "C:\\Windows\\Temp\\movies1.htm", true);
var b = new Browser();
b.Navigate("file:///c:/Windows/Temp/movies1.htm");
Assert.AreEqual(b.Select("ul#menu>li").Count(), 3);
b.Navigate("file:///c|/Windows/Temp/movies1.htm");
Assert.AreEqual(b.Select("ul#menu>li").Count(), 3);
b.Navigate("file:///c|\\Windows\\Temp\\movies1.htm");
Assert.AreEqual(b.Select("ul#menu>li").Count(), 3);
b.Navigate("file://\\c|\\Windows\\Temp\\movies1.htm");
Assert.AreEqual(b.Select("ul#menu>li").Count(), 3);
}
}
示例13: SampleApp
public void SampleApp()
{
Browser b = new Browser(Helper.GetMoviesRequestMocker());
HttpRequestLog lastRequest = null;
b.RequestLogged += (br, l) =>
{
lastRequest = l;
};
b.Navigate("http://localhost/movies/");
var link = b.Find(ElementType.Anchor, FindBy.Text, "Create New");
link.Click();
var box = b.Select("input[name=Title]");
box.Value = "1234";
box = b.Select("input[name=ReleaseDate]");
box.Value = "2011-01-01";
box = b.Select("input[name=Genre]");
box.Value = "dark";
box = b.Select("input[name=Price]");
box.Value = "51";
box = b.Select("input[name=Rating]");
box.Value = "***";
link = b.Select("input[type=submit]");
link.Click();
Assert.That(b.LastWebException == null, "Webexception detected");
Assert.That(lastRequest.PostBody.Contains("&Price=51&"));
}
示例14: GetAttribute_Backdoor_FrameHandle
public void GetAttribute_Backdoor_FrameHandle()
{
Browser b = new Browser(Helper.GetFramesMock());
HttpRequestLog lastRequest = null;
b.RequestLogged += (br, l) =>
{
lastRequest = l;
};
b.Navigate("http://localhost/");
var elm = b.Select("iframe");
string handle = elm.GetAttribute("SimpleBrowser.WebDriver:frameWindowHandle");
Assert.AreEqual(handle, "frame1");
}
示例15: Forms_Form_Attribute
public void Forms_Form_Attribute()
{
Browser b = new Browser();
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.HTML5Elements.htm"));
// This test covers the following cases:
// 1. An input outside of the form with the form attribute is submitted.
// 2. An input in another form with the form attribute is submitted.
var field1 = b.Find("field1");
field1.Value = "Name1";
var field1a = b.Find("field1a");
field1a.Value = "Name1a";
var field2 = b.Find("field2");
field2.Value = "Name2";
var submit1 = b.Find("submit1");
ClickResult clickResult = submit1.Click();
// Check to make sure the form submitted.
Assert.IsTrue(clickResult == ClickResult.SucceededNavigationComplete);
var names = b.Select("td.desc");
var values = b.Select("td.val");
Assert.IsTrue(names.Count() == values.Count());
Assert.IsTrue(values.Where(e => e.Value == "Name1").FirstOrDefault() != null);
Assert.IsTrue(values.Where(e => e.Value == "Name2").FirstOrDefault() != null);
Assert.IsTrue(values.Where(e => e.Value == "Name1a").FirstOrDefault() != null);
Assert.IsTrue(values.Where(e => e.Value == "Submit1").FirstOrDefault() != null);
// This test covers the following cases:
// 1. An input in the form with a form element corresponding to another form is not submitted.
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.HTML5Elements.htm"));
field2 = b.Find("field2");
field2.Value = "Name2";
var field2a = b.Find("field2a");
field2a.Value = "Name2a";
var submit2 = b.Find("submit2");
clickResult = submit2.Click();
// Check to make sure the form submitted.
Assert.IsTrue(clickResult == ClickResult.SucceededNavigationComplete);
names = b.Select("td.desc");
values = b.Select("td.val");
Assert.IsTrue(values.Where(e => e.Value == "Submit2").FirstOrDefault() != null);
Assert.IsTrue(values.Where(e => e.Value == "Name2a").FirstOrDefault() != null);
Assert.IsFalse(values.Where(e => e.Value == "Name2").FirstOrDefault() != null);
}