using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Support.PageObjects;
namespace SearchEngineCalculator
public static void Main()
IWebDriver driver = new ChromeDriver();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("www.bing.com");
driver.FindElement(By.Id("sb_form_q")).SendKeys("Calculator");
driver.FindElement(By.Id("sb_form_go")).Click();
WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
wait.Until(d => d.FindElement(By.Id("rcTB")));
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string title = (string)js.ExecuteScript("document.getElementById('rcTB').textContent= " + 12 + " " + "+" + " " + 3);
driver.FindElement(By.Id("rcEquals")).Click();
string output = driver.FindElement(By.Id("rcTB")).Text;
public static IWebDriver Driver
public OnlineCalc(IWebDriver driver)
[FindsBy(How = How.Custom, Using = "rcOne", CustomFinderType = typeof (CustomBy))]
public static IWebElement ButtonOne
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonTwo
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonThree
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonFour
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonFive
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonSix
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonSeven
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonEight
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonNine
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonPeriod
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonEqualsTo
[FindsBy(How = How.Id, Using = "")]
public static IWebElement TextCalcResult
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonAdd
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonMinus
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonMultiply
[FindsBy(How = How.Id, Using = "")]
public static IWebElement ButtonDivide
public string Calculate(double firstNum, double secondNum, CalOperations operation)
PressValueInCalc(firstNum);
PerformOperation(operation);
PressValueInCalc(secondNum);
return TextCalcResult.Text;
private void PressValueInCalc(double number)
var numInChar = number.ToString().ToArray();
foreach (var num in numInChar)
var isNumOrSymbol = int.TryParse(num.ToString(), out itsNum);
private void PerformOperation(CalOperations operation)
case CalOperations.Multiply:
case CalOperations.Division:
case CalOperations.Substract:
public enum CalOperations
public class CustomBy : By
public CustomBy(string customByString)
FindElementMethod = context =>
IWebElement mockElement = OnlineCalc.Driver.FindElement(By.Id(customByString));