OpenQA.Selenium.By.TagName C# (CSharp) Method

TagName() public static method

Gets a mechanism to find elements by their tag name.
public static TagName ( string tagNameToFind ) : By
tagNameToFind string The tag name to find.
return By
        public static By TagName(string tagNameToFind)
        {
            if (tagNameToFind == null)
            {
                throw new ArgumentNullException("tagNameToFind", "Cannot find elements when name tag name is null.");
            }

            By by = new By();
            by.findElementMethod =
                (ISearchContext context) => ((IFindsByTagName)context).FindElementByTagName(tagNameToFind);
            by.findElementsMethod =
                (ISearchContext context) => ((IFindsByTagName)context).FindElementsByTagName(tagNameToFind);

            by.description = "By.TagName: " + tagNameToFind;
            return by;
        }

Usage Example

Exemplo n.º 1
0
        public bool selectByOptionText(By locator, string value, string locatorName)
        {
            bool flag = false;

            try
            {
                WebElement ListBox = driver.FindElement(locator);
                IReadOnlyCollection <WebElement> options = ListBox.FindElements(By.TagName("option"));
                foreach (var option in options)
                {
                    string opt = option.Text.Trim();
                    if (opt.ToLower().Equals(value.ToLower().Trim()))
                    {
                        option.Click();
                        flag = true;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(Path.Combine(projectLoc, TestContext.CurrentContext.Test.Name + "-" + DateTime.Now.ToString("dd-M-yyyy", CultureInfo.InvariantCulture) + "." + format), format);
                throw new Exception("Option with value attribute " + value + " is Not Select from the DropDown " + locatorName + " " + e.Message);
            }
            return(flag);
        }
All Usage Examples Of OpenQA.Selenium.By::TagName