Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Last active September 24, 2017 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelovstanton/262b806b99abf783d5b5b01645879a94 to your computer and use it in GitHub Desktop.
Save angelovstanton/262b806b99abf783d5b5b01645879a94 to your computer and use it in GitHub Desktop.
private void PerformTestOperations(IWebDriver driver)
{
string testPagePath =
"http://htmlpreview.github.io/?https://github.com/angelovstanton/AutomateThePlanet/blob/master/WebDriver-Series/TestPage.html";
driver.Navigate().GoToUrl(testPagePath);
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(10);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
var textBoxes = driver.FindElements(By.Name("fname"));
foreach (var textBox in textBoxes)
{
textBox.SendKeys(Guid.NewGuid().ToString());
}
var selects = driver.FindElements(By.TagName("select"));
foreach (var select in selects)
{
var selectElement = new SelectElement(select);
selectElement.SelectByText("Mercedes");
}
var submits = driver.FindElements(By.XPath("//input[@type='submit']"));
foreach (var submit in submits)
{
submit.Click();
}
var colors = driver.FindElements(By.XPath("//input[@type='color']"));
foreach (var color in colors)
{
SetValueAttribute(driver, color, "#000000");
}
var dates = driver.FindElements(By.XPath("//input[@type='date']"));
foreach (var date in dates)
{
SetValueAttribute(driver, date, "2020-06-01");
}
var radioButtons = driver.FindElements(By.XPath("//input[@type='radio']"));
foreach (var radio in radioButtons)
{
radio.Click();
}
}
private void SetValueAttribute(IWebDriver driver, IWebElement element, string value)
{
SetAttribute(driver, element, "value", value);
}
private void SetAttribute(IWebDriver driver, IWebElement element, string attributeName, string attributeValue)
{
driver.ExecuteJavaScript
(
"arguments[0].setAttribute(arguments[1], arguments[2]);",
element,
attributeName,
attributeValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment