public DataTable GetTableElement(MediumCommandArguments search, TimeSpan timeout) { var element = GetElementInFrame(search, timeout); if (element == null) { throw new Exception("Cannot find the HTML element. Try to change the search phrase or \"by\" argument value so that the correct element is found"); } else if (element.TagName != "table") { throw new Exception($"The element found has the \"{element.TagName}\" tag name. Try to change the search phrase so that the \"table\" element is found instead"); } var dataTable = new DataTable(); var trElements = element.FindElements(By.TagName("tr")); dataTable = AddColumnNamesFromThElements(dataTable, trElements[0].FindElements(By.TagName("th"))); foreach (var trElement in trElements) { var tdElements = trElement.FindElements(By.TagName("td")); dataTable = AddColumnsIfThereAreMoreTdElements(dataTable, tdElements.Count); dataTable = AddRowToDataTable(dataTable, tdElements); } return(dataTable); }
public void TypeText(string text, MediumCommandArguments search, TimeSpan timeout) { var elem = GetElementInFrame(search, timeout); elem.SendKeys(text); if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false) { webDriver.SwitchTo().DefaultContent(); } }
private IWebElement GetElementInFrame(MediumCommandArguments search, TimeSpan timeout) { PreCheckCurrentWindowHandle(); if (!string.IsNullOrEmpty(search.IFrameSearch?.Value)) { webDriver.SwitchTo().Frame(FindElement(search.IFrameSearch.Value, search.IFrameBy.Value, timeout)); } var element = FindElement(search.Search.Value, search.By.Value, timeout); return(element); }
public string GetTextValue(MediumCommandArguments search, TimeSpan timeout) { var element = GetElementInFrame(search, timeout); var res = element?.Text ?? string.Empty; if (!string.IsNullOrEmpty(search.IFrameSearch?.Value)) { webDriver.SwitchTo().DefaultContent(); } return(res); }
public string GetAttributeValue(string attributeName, MediumCommandArguments search) { var element = GetElementInFrame(search, search.Timeout.Value); var result = element?.GetAttribute(attributeName); if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false) { webDriver.SwitchTo().DefaultContent(); } return(result ?? string.Empty); }
public void Click(MediumCommandArguments search, TimeSpan timeout, bool waitForNewWindow = false) { NewPopupWindowHandler popupHandler = new NewPopupWindowHandler(webDriver); var elem = GetElementInFrame(search, timeout); Actions actions = new Actions(webDriver); actions.MoveToElement(elem).Click().Build().Perform(); if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false) { webDriver.SwitchTo().DefaultContent(); } popupHandler.Finish(waitForNewWindow, timeout); }
public void PressKey(string keyText, MediumCommandArguments search, TimeSpan timeout) { NewPopupWindowHandler popupHandler = new NewPopupWindowHandler(webDriver); var elem = GetElementInFrame(search, timeout); string convertedText = typeof(Keys).GetFields().Where(x => x.Name.ToLower() == keyText.ToLower()).FirstOrDefault()?.GetValue(null) as string; if (convertedText == null) { throw new ArgumentException($"Wrong key argument '{keyText}' specified. Please use keys allowed by selenium library."); } elem.SendKeys(convertedText); if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false) { webDriver.SwitchTo().DefaultContent(); } popupHandler.Finish(); }
public void CallFunction(string functionName, object[] arguments, string type, MediumCommandArguments search, TimeSpan timeout) { NewPopupWindowHandler popupHandler = new NewPopupWindowHandler(webDriver); PreCheckCurrentWindowHandle(); if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false) { webDriver.SwitchTo().Frame(FindElement(search.IFrameSearch.Value, search.IFrameBy.Value, timeout)); } IWebElement element = FindElement(search.Search.Value, search.By.Value, timeout); element?.CallFunction(functionName, arguments, type); if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false) { webDriver.SwitchTo().DefaultContent(); } popupHandler.Finish(); }
public string GetOuterHtml(MediumCommandArguments search) { return(GetAttributeValue("outerHTML", search)); }
public void SetAttributeValue(string attributeName, string attributeValue, AttributeOperationType setAttributeType, MediumCommandArguments search, TimeSpan timeout) { var element = GetElementInFrame(search, timeout); if (element != null) { if (IsAttributeOprtationType(element, attributeName, setAttributeType)) { element.SetAttribute(attributeName, attributeValue); } else { element.SetProperty(attributeName, attributeValue); } } if (string.IsNullOrEmpty(search.IFrameSearch?.Value) == false) { webDriver.SwitchTo().DefaultContent(); } }