Friday, March 10, 2017

Selenium WebDriver – Working with the checkbox element (C#)

תוצאת תמונה עבור ‪selenium testing‬‏The checkbox element, is a graphical control element that permits the user to make a choice between one or more possible mutually exclusive options, selenium WebDriver support this element and provides set of methods that simulate any manual task.

HTML Code
<label> <input type="checkbox" id="cbox1" value=""> Checkbox 1</label><br>
<label><input type="checkbox" id="cbox2" value=""> Checkbox 2</label><br>
<label><input type="checkbox" id="cbox3" value=""> Checkbox 3</label><br>
<label><input type="checkbox" id="cbox4" value=""> Checkbox 4</label><br>

Code
[TestMethod]
public void CheckboxExample()
{
foreach (var checkbox in Firefox.FindElements(By.XPath("//input[@*='checkbox']")))
{
// Validation that all checkboxes are unchecked (Default)
Assert.IsTrue(!(checkbox.Selected));

//selecting each checkbox
checkbox.Click();

//Validation that all checkboxes are now selected
Assert.IsTrue(checkbox.Selected);
}}

1 comment:

  1. Hello David,
    The Article on Selenium WebDriver Working with the checkbox element is very informative give detail information about it.Thanks for Sharing the information about Selenium Web Driver Working. Software Testing Services

    ReplyDelete

My Presentations