public static string ReadFromWebelement(string ElementName, string Attribute) { string Text = ""; try { string ElementLocator = AllPages.getElementLocator(ElementName); WaitToAppear(ElementLocator); IWebElement WebElement = WebDriver.FindElement(By.CssSelector(ElementLocator)); if (Attribute == "text") { Text = WebElement.Text; } if (Attribute == "attributetext") { Text = WebElement.GetAttribute("text"); } if (Attribute == "attributevalue") { Text = WebElement.GetAttribute("value"); } Console.WriteLine(Text + " read from element with locator " + ElementLocator); return(Text); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(Text); } }
public static void SafeSelectWebelement(string ElementName, string Action) { try { string ElementLocator = AllPages.getElementLocator(ElementName); WaitToAppear(ElementLocator); IWebElement WebElement = WebDriver.FindElement(By.CssSelector(ElementLocator)); if (Action == "click") { WebElement.Click(); } else { if (Action == "safeclick") { WebElement.Click(); } if (Action == "enter") { WebElement.SendKeys(Keys.Enter); } if (Action == "return") { WebElement.SendKeys(Keys.Return); } } Console.WriteLine("Selected the element with locator" + ElementLocator + " with " + Action); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void UploadFile(string FilePath, string ElementName) { try { string ElementLocator = AllPages.getElementLocator(ElementName); WebDriver.FindElement(By.CssSelector(ElementLocator)).SendKeys(FilePath); Console.WriteLine("Uploaded the file with path " + FilePath + " to element with locator " + ElementLocator); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void SelectFromDropDownByClick(string DropDownName, string OptionName) { try { string DropDownLocator = AllPages.getElementLocator(DropDownName); string OptionLocator = AllPages.getElementLocator(OptionName); SelectWebElement(DropDownLocator); SelectWebElement(OptionLocator); Console.WriteLine("Selected the element with locator " + OptionLocator + " from dropdown with locator " + DropDownLocator); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void EnterInToWebelement(string Entry, string ElementName) { try { string ElementLocator = AllPages.getElementLocator(ElementName); WaitToAppear(ElementLocator); IWebElement WebElement = WebDriver.FindElement(By.CssSelector(ElementLocator)); WebElement.SendKeys(Entry); Console.WriteLine(Entry + " entered into the element with locator " + ElementLocator); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void SelectFromDropDownBySelect(string OptionText, string DropDownName) { try { string DropDownLocator = AllPages.getElementLocator(DropDownName); IWebElement DropDown = WebDriver.FindElement(By.CssSelector(DropDownLocator)); SelectElement Select = new SelectElement(DropDown); Select.SelectByText(OptionText); Console.WriteLine("Selected the element with text " + OptionText + " from dropdown with locator " + DropDownLocator); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void SelectCheckBox(string CheckBoxName) { try { string CheckBoxLocator = AllPages.getElementLocator(CheckBoxName); SelectWebElement(CheckBoxLocator); IWebElement RadioButton = WebDriver.FindElement(By.CssSelector(CheckBoxLocator)); if (RadioButton.Selected) { Console.WriteLine("Selected"); } else { Console.WriteLine("UnSelected"); } Console.WriteLine("Selected the CheckBox with locator " + CheckBoxLocator); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void SelectRadioButton(string RadioButtonName) { try { string RadioButtonLocator = AllPages.getElementLocator(RadioButtonName); SelectWebElement(RadioButtonLocator); IWebElement RadioButton = WebDriver.FindElement(By.CssSelector(RadioButtonLocator)); if (RadioButton.GetAttribute("checked") == "checked") { Console.WriteLine("Checked"); } else { Console.WriteLine("UnChecked"); } Console.WriteLine("Selected the RadioButton with locator " + RadioButtonLocator); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void SelectFromDropDownByText(string DropDownName, string OptionsLocator, string OptionText) { try { string DropDownLocator = AllPages.getElementLocator(DropDownName); SelectWebElement(DropDownLocator); IList <IWebElement> Options = WebDriver.FindElements(By.CssSelector(OptionsLocator)); foreach (var Option in Options) { if (Option.Text == OptionText) { Option.Click(); } } Console.WriteLine("Selected the element with text " + OptionText + " from dropdown with locator " + DropDownLocator); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }