/// <summary> /// Finds an element using the element name. /// </summary> /// <param name="driver">The <see cref="IWebDriver"/> to use in finding the element.</param> /// <param name="use">The locator string to use.</param> /// <returns>An <see cref="IWebElement"/> that matches the locator string.</returns> public IWebElement Find(OpenQA.Selenium.IWebDriver driver, string use) { string[] parts = use.Split(new char[] { ' ' }); ReadOnlyCollection<IWebElement> allElements = driver.FindElements(By.Name(parts[0])); IList<IWebElement> filteredElements = new List<IWebElement>(allElements); for (int i = 1; i < parts.Length; i++) { IFilterFunction filterBy = this.GetFilterFunction(parts[i]); if (filterBy == null) { throw new SeleniumException(use + " not found. Cannot find filter for: " + parts[i]); } string filterValue = this.GetFilterValue(parts[i]); filteredElements = filterBy.FilterElements(allElements, filterValue); } if (filteredElements != null && filteredElements.Count > 0) { return filteredElements[0]; } throw new SeleniumException(use + " not found"); }
internal void IntializeDriver(ref OpenQA.Selenium.IWebDriver driver, ref bool IsBrowserDimendion, ref List<OpenQA.Selenium.IWebDriver> driverlist, ref int width, ref int height) { driver = new SafariDriver(); driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150)); driver.Manage().Window.Maximize(); if (IsBrowserDimendion) driver.Manage().Window.Size = new System.Drawing.Size(width, height); driverlist.Add(driver); }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { if (!string.IsNullOrEmpty(Value)) { Target = Target + "|text=" + Value; } IWebElement[] elements; try { elements = new Utility(1).GetTargetElements(driver, Target); } catch (StaleElementReferenceException ex) { //retrying elements = new Utility(1).GetTargetElements(driver, Target); } if (elements.Length > 1) return new CommandExecutionResult { CommandResult = CommandResult.ResultYieldedMoreThanOne, Message = string.Format("More than one element found for target:{0} value:{1}", Target, Value) }; if (elements.Length == 1) return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) }; return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { int timeout = 10; bool isFound = false; if (!string.IsNullOrEmpty(Value)) { Target = Target + "|text=" + Value; } IWebElement[] elements; try { isFound= new Utility().WaitingForElement(driver, Target, timeout); } catch (StaleElementReferenceException ex) { //retrying isFound = new Utility().WaitingForElement(driver, Target, timeout); } if (!isFound) return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) }; return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }
public Messages.BaseResult ExecuteTest(OpenQA.Selenium.IWebDriver driverToTest, Parser.TestItem itemToTest) { BaseResult br = new BaseResult(); try { SeleniumHtmlHelper helper = new SeleniumHtmlHelper(driverToTest); if (helper.IsAlertPresent()) { string alertText = helper.GrabTextFromAlertAndClose(acceptAlert: true); Assert.AreEqual(itemToTest.Selector, alertText); } else { throw new Exception("Alert not present"); } br.Status = true; br.Message = "OK"; } catch (Exception e) { #if DEBUG throw; #endif br.Status = false; br.Message = string.Format("Exception type: {0}. Message: {1}.", e.GetType(), e.Message); } return br; }
public void ShouldCreateSelector(OpenQA.Selenium.By selector) { // Given // When // Then Assert.NotNull(selector); }
public void Click(OpenQA.Selenium.Interactions.Internal.ICoordinates where) { IWebElement elm = where.AuxiliaryLocator as IWebElement; if (elm != null) { elm.Click(); } }
public static IWebElement PerformActionOn(this IWebDriver browser, OpenQA.Selenium.By by, Action<IWebElement> actionToPerform) { var element = browser.FindElement(@by); actionToPerform(element); return element; }
/// <summary> /// Finds an element using the ID and name. /// </summary> /// <param name="driver">The <see cref="IWebDriver"/> to use in finding the element.</param> /// <param name="use">The locator string to use.</param> /// <returns>An <see cref="IWebElement"/> that matches the locator string.</returns> /// <remarks>This method looks up elements first by ID, then by name.</remarks> public IWebElement Find(OpenQA.Selenium.IWebDriver driver, string use) { try { return new IdLookupStrategy().Find(driver, use); } catch (NoSuchElementException) { return new NameLookupStrategy().Find(driver, use); } }
/// <summary> /// looks for dom objects to comment on twitter /// </summary> /// <param name="startSearch">Dom</param> /// <param name="uName">name</param> /// <param name="uPass">pass</param> /// <param name="derValue">bbot utility value/login value</param> internal static void Run(OpenQA.Selenium.IWebDriver startSearch, string uName, string uPass, int derValue) { IWebDriver startDerSeach = BBotUtility.LogMeIn(startSearch, uName, uPass, derValue); IWebElement findDerEle; startDerSeach.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10.0)); findDerEle = startDerSeach.FindElement(By.XPath("//div[@id='tweet-box-mini-home-profile']")); findDerEle.Click(); findDerEle.SendKeys(TwitSpecial); System.Threading.Thread.Sleep(1000); findDerEle = startDerSeach.FindElement(By.XPath("//button[@class='btn primary-btn tweet-action js-tweet-btn']")); findDerEle.Click(); }
private static bool IsElementPresent(OpenQA.Selenium.IWebDriver driver, By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { if (!string.IsNullOrEmpty(Value)) { Target = Target + "|text=" + Value; } IWebElement[] elements = new IWebElement[0]; try { elements = new Utility().GetTargetElements(driver, Target); } catch (StaleElementReferenceException ex) { //retrying System.Diagnostics.Debug.WriteLine("Retrying.."); elements = new Utility().GetTargetElements(driver, Target); } finally { if (elements.Length == 1) { try { elements.First().Click(); } catch (ElementNotVisibleException ex) { elements = new Utility(0).GetTargetElements(driver, Target); elements.First().Click(); } } } if (elements.Length > 1) return new CommandExecutionResult { CommandResult = CommandResult.ResultYieldedMoreThanOne, Message = string.Format("More than one element found for target:{0} value:{1}", Target, Value) }; if (elements.Length == 0) return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) }; return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }
public override void Funcao(OpenQA.Selenium.IWebDriver pagina) { IWebElement elemento = GetElemento(pagina); IList<IWebElement> AllDropDownList = elemento.FindElements(By.TagName("li")); foreach (var item in AllDropDownList) { if (item.Text.ToUpper() == selectValue.ToUpper()) { item.Click(); break; } } }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { bool isFound = false; IWebElement[] elements = null; try { elements = new Utility().GetTargetElements(driver, Target); } catch (StaleElementReferenceException ex) { //retrying elements = new Utility().GetTargetElements(driver, Target); } finally { if (elements.Length == 1) { var elements2 = elements.First().FindElements(By.TagName("option")); foreach (IWebElement el in elements2) { if (el.Text == Value) { el.Click(); isFound = true; break; } } } } if (elements.Length==0) return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) }; if (isFound) return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; else return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }
/// <summary> /// input type="text"への入力・削除 /// </summary> /// <param name="driver"></param> /// <param name="elementId"></param> /// <param name="value"></param> private static void EditTextField(OpenQA.Selenium.IWebDriver driver) { var element = driver.FindElement(OpenQA.Selenium.By.Id("id_input_text")); // <input type="text">へデータを設定 // なお、既にデータがあったり複数回の入力の場合、 // データは追記されていく element.SendKeys("テキスト"); element.SendKeys("txt"); // <input type="text">のデータ削除 element.Clear(); }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { driver.Navigate().GoToUrl(Target); return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }
/// <summary> /// runs procedure to automate comment on social media based on selection /// </summary> /// <param name="startSearch"></param> /// <param name="uName">name</param> /// <param name="uPass">psswrd</param> /// <param name="Dervalue">selection value/ what site chosen</param> internal static void RunApp(OpenQA.Selenium.IWebDriver startSearch, string uName, string uPass, int Dervalue) { switch (Dervalue) { // need to change to a generic method instead of this case 1: BrowserbotLinkedin.Run(startSearch, uName, uPass, Dervalue); break; case 2: BrowserbotGooglePlus.Run(startSearch, uName, uPass, Dervalue); break; case 3: BrowserbotFacebook.Run(startSearch, uName, uPass, Dervalue); break; case 4: BrowserbotTwitter.Run(startSearch, uName, uPass, Dervalue); break; } }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { int waitTime = 0; bool result = int.TryParse(Value, out waitTime); Thread.Sleep(waitTime * 1000); return new CommandExecutionResult { CommandResult = CommandResult.Success }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { if (driver.Url.ToLower() != Target.ToLower()) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = "Url not the same - expecting " + Target.ToLower() + " but was " + driver.Url.ToLower() }; } return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }
public Messages.BaseResult ExecuteTest(OpenQA.Selenium.IWebDriver driverToTest, Parser.TestItem itemToTest) { BaseResult br = new BaseResult(); try { SeleniumHtmlHelper helper = new SeleniumHtmlHelper(browserDriver: driverToTest); helper.ElementLocator(itemToTest.Selector).Click(); br.Status = true; br.Message = "OK"; } catch (Exception e) { #if DEBUG throw; #endif br.Status = false; br.Message = string.Format("Exception type: {0}. Message: {1}.", e.GetType(), e.Message); } return br; }
//may need to change this method to generic /// <summary> /// searches DOM in order to comment /// </summary> /// <param name="startSearch">iweb driver that contains ff/DOM</param> /// <param name="uName">name</param> /// <param name="uPass">pass</param> /// <param name="derValue">value for switch/case to log in</param> internal static void Run(OpenQA.Selenium.IWebDriver startSearch, string uName, string uPass, int derValue) { IWebDriver startDerSearch = BBotUtility.LogMeIn(startSearch, uName, uPass, derValue); IWebElement findEle; startDerSearch.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5.0)); System.Threading.Thread.Sleep(3000); // changed this to a config file since this may change startDerSearch.Navigate().GoToUrl("https://www.facebook.com/?sk=nf"); findEle = startDerSearch.FindElement(By.XPath("//textarea[@name='xhpc_message']")); startDerSearch.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10.0)); findEle.Click(); findEle = startDerSearch.FindElement(By.XPath("//textarea[@name='xhpc_message_text']")); System.Threading.Thread.Sleep(2000); findEle.SendKeys(ChosenWord); findEle = startDerSearch.FindElement(By.XPath("//li/button[@type='submit']")); findEle.Click(); }
public Messages.BaseResult ExecuteTest(OpenQA.Selenium.IWebDriver driverToTest, Parser.TestItem itemToTest) { BaseResult br = new BaseResult(); try { double pauseLenghtMs = double.Parse(itemToTest.Value); System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(pauseLenghtMs)); br.Status = true; br.Message = "OK"; } catch (Exception e) { #if DEBUG throw; #endif br.Status = false; br.Message = string.Format("Exception type: {0}. Message: {1}.", e.GetType(), e.Message); } return br; }
/// <summary> /// runs all 4 social media sites by selecting website/navigating to and running Run app method /// </summary> /// <param name="Dervalue">the value of 5</param> /// <param name="startSearch">i web driver DOM of page</param> internal static void RunAllSocialMediaSites(int Dervalue, OpenQA.Selenium.IWebDriver startSearch) { //BBotChecker nr = new BBotChecker(); string uName ="", uPass =""; Dervalue -= 1 ; for (int socialRun = 1; Dervalue >= socialRun ; socialRun++) { //needed to set radio value that selectwebaddress depends on var mediaSite = BBotChecker.SetRadioName(socialRun); // sets the url System.Threading.Thread.Sleep(10000); BBotChecker.SelectWebAddress(mediaSite); startSearch.Navigate().GoToUrl(BBotChecker.SetURL); uPass = BBotChecker.Passwords[socialRun -1]; uName = BBotChecker.Usernames[socialRun -1 ]; RunApp(startSearch, uName, uPass, socialRun); } }
public Messages.BaseResult ExecuteTest(OpenQA.Selenium.IWebDriver driverToTest, Parser.TestItem itemToTest) { BaseResult br = new BaseResult(); try { Assert.AreEqual(itemToTest.Selector, driverToTest.Title); br.Status = true; br.Message = "OK"; } catch (Exception e) { #if DEBUG throw; #endif br.Status = false; br.Message = string.Format("Exception type: {0}. Message: {1}.", e.GetType(), e.Message); } return br; }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { IWebElement[] elements; try { elements = new Utility().GetTargetElements(driver, Target); } catch (StaleElementReferenceException ex) { //retrying elements = new Utility().GetTargetElements(driver, Target); } IWebElement[] elements2; try { elements2 = new Utility().GetTargetElements(driver, Target); } catch (StaleElementReferenceException ex) { //retrying elements2 = new Utility().GetTargetElements(driver, Target); } if (elements.Length == 0 || elements2.Length == 0) return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Error Command: {1} Cannot find targets.", "DragAndDrop") }; if (elements.Length > 1 || elements2.Length > 1) return new CommandExecutionResult { CommandResult = CommandResult.ResultYieldedMoreThanOne, Message = string.Format("More than one element found for targets") }; (new Actions(driver)).DragAndDrop(elements.First(), elements2.First()).Perform(); return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message + "\n" + ex.StackTrace }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message + "\n" + ex.StackTrace }; } }
public Messages.BaseResult ExecuteTest(OpenQA.Selenium.IWebDriver driverToTest, Parser.TestItem itemToTest) { BaseResult br = new BaseResult(); try { SelectElement selectList; IWebElement element; SeleniumHtmlHelper helper = new SeleniumHtmlHelper(browserDriver: driverToTest); element = helper.ElementLocator(itemToTest.Selector); selectList = new SelectElement(element); if (itemToTest.Value.StartsWith("label=")) { selectList.SelectByText(itemToTest.Value.Replace("label=", "")); } else if (itemToTest.Value.StartsWith("value=")) { selectList.SelectByValue(itemToTest.Value.Replace("value=", "")); } else if (itemToTest.Value.StartsWith("id=")) { element.FindElement(By.XPath(string.Format(@"option[@id='{0}']", itemToTest.Value.Replace("id=", "")))); } else if (itemToTest.Value.StartsWith("index=")) { int index = int.Parse(itemToTest.Value.Replace("index=", "")); selectList.SelectByIndex(index); } br.Status = true; br.Message = "OK"; } catch (Exception e) { #if DEBUG throw; #endif br.Status = false; br.Message = string.Format("Exception type: {0}. Message: {1}.", e.GetType(), e.Message); } return br; }
public Messages.BaseResult ExecuteTest(OpenQA.Selenium.IWebDriver driverToTest, Parser.TestItem itemToTest) { BaseResult br = new BaseResult(); try { string domainUrl = new Uri(driverToTest.Url).GetLeftPart(UriPartial.Authority); // TODO: Modify passing of the base url? Is it really necessary? Input parameter? driverToTest.Navigate().GoToUrl(domainUrl + itemToTest.Selector); br.Status = true; br.Message = "OK"; } catch (Exception e) { #if DEBUG throw; #endif br.Status = false; br.Message = string.Format("Exception type: {0}. Message: {1}.", e.GetType(), e.Message); } return br; }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { string v = Value.Contains("$randomNumber") ? Value.Replace("$randomNumber", r.Next(100000, 999999).ToString()) : Value; IWebElement[] elements; try { elements = new Utility().GetTargetElements(driver, Target); } catch (StaleElementReferenceException ex) { //retrying elements = new Utility().GetTargetElements(driver, Target); } if (elements.Length == 0) return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) }; if (elements.Length > 1) return new CommandExecutionResult { CommandResult = CommandResult.ResultYieldedMoreThanOne, Message = string.Format("More than one element found for target:{0} value:{1}", Target, Value) }; elements.First().Clear(); elements.First().SendKeys(v.Remove(v.Length - 2)); //minimum of two letters for (int i = v.Length - 2; i < v.Length; i++ ) { elements.First().SendKeys(v[i].ToString()); Thread.Sleep(1000); } return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { IWebElement[] elements; try { elements = new Utility().GetTargetElements(driver, Target); } catch (StaleElementReferenceException ex) { //retrying elements = new Utility().GetTargetElements(driver, Target); } if (elements.Length > 1) return new CommandExecutionResult { CommandResult = CommandResult.ResultYieldedMoreThanOne, Message = string.Format("More than one element found for target:{0} value:{1}", Target, Value) }; if (elements.Length == 0) return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) }; string text = elements.First().Text; if (RuntimeValues.ContainsKey(Value)) { RuntimeValues[Value] = text; } else { RuntimeValues.Add(Value, text); } return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver) { try { var o = new Utility().ExecuteScript(driver, Target, Value); if (!string.IsNullOrEmpty(Value)) { if (!Value.Equals(o.ToString(), StringComparison.CurrentCultureIgnoreCase)) { return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) }; } } return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty }; } catch (TimeoutException ex) { return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message }; } catch (Exception ex) { return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message }; } }