Class Selectors

java.lang.Object
com.codeborne.selenide.Selectors

public class Selectors extends Object
  • Constructor Details

    • Selectors

      public Selectors()
  • Method Details

    • withText

      public static org.openqa.selenium.By withText(String elementText)
      Find element CONTAINING given text (as a substring).

      This method ignores difference between space, \n, \r, \t and   This method ignores multiple spaces.

      Parameters:
      elementText - Text to search inside element
      Returns:
      standard selenium By criteria`
    • withTagAndText

      public static org.openqa.selenium.By withTagAndText(String tag, String elementText)
      Find element CONTAINING given text (as a substring).

      This method ignores difference between space, \n, \r, \t and   This method ignores multiple spaces.

      Parameters:
      tag - Html tag name (e.g. "dev", "span", "li", "a", "td")
      elementText - Text to search inside element
      Returns:
      standard selenium By criteria`
    • withTextCaseInsensitive

      public static org.openqa.selenium.By withTextCaseInsensitive(String elementText)
      Same as withText(String), but case-insensitive.
    • byText

      public static org.openqa.selenium.By byText(String elementText)
      Find element that has given text (the whole text, not a substring).

      This method ignores difference between space, \n, \r, \t and   This method ignores multiple spaces. This method is case-sensitive.

      Parameters:
      elementText - Text that searched element should have
      Returns:
      standard selenium By criteria
    • byTagAndText

      public static org.openqa.selenium.By byTagAndText(String tag, String elementText)
      Find element that has given text (the whole text, not a substring).

      This method ignores difference between space, \n, \r, \t and   This method ignores multiple spaces. This method is case-sensitive.

      Parameters:
      tag - Html tag name (e.g. "dev", "span", "li", "a", "td")
      elementText - Text that searched element should have
      Returns:
      standard selenium By criteria
    • byTextCaseInsensitive

      public static org.openqa.selenium.By byTextCaseInsensitive(String elementText)
      Same as byText(String), but case-insensitive.
    • byAttribute

      public static org.openqa.selenium.By byAttribute(String attributeName, String attributeValue)
      Find elements having attribute with given value.

      Examples: <div binding="fieldValue"></div> Find element with attribute 'binding' EXACTLY containing text 'fieldValue' , use: byAttribute("binding", "fieldValue")

      For finding difficult/generated data attribute which contains some value: <div binding="userName17fk5n6kc2Ds45F40d0fieldValue_promoLanding word"></div>

      Find element with attribute 'binding' CONTAINING text 'fieldValue', use symbol '*' with attribute name: byAttribute("binding*", "fieldValue") it same as By.cssSelector("[binding*='fieldValue']")

      Find element whose attribute 'binding' BEGINS with 'userName', use symbol '^' with attribute name: byAttribute("binding^", "fieldValue")

      Find element whose attribute 'binding' ENDS with 'promoLanding', use symbol '$' with attribute name: byAttribute("binding$", "promoLanding")

      Find element whose attribute 'binding' CONTAINING WORD 'word': byAttribute("binding~", "word")

      Seems to work incorrectly if attribute name contains dash, for example: <option data-mailServerId="123"></option>

      Parameters:
      attributeName - name of attribute, should not be empty or null
      attributeValue - value of attribute, should not contain both apostrophes and quotes
      Returns:
      standard selenium By cssSelector criteria
    • shadowCss

      public static org.openqa.selenium.By shadowCss(String target, String shadowHost, String... innerShadowHosts)
      See Also:
    • shadowDeepCss

      public static org.openqa.selenium.By shadowDeepCss(String target)
      See Also:
    • by

      public static org.openqa.selenium.By by(String attributeName, String attributeValue)
      Synonym for #byAttribute
    • byTitle

      public static org.openqa.selenium.By byTitle(String title)
      Find element with given title ("title" attribute)
    • byValue

      public static org.openqa.selenium.By byValue(String value)
      Find input element with given value ("value" attribute)
    • byName

      public static org.openqa.selenium.By byName(String name)
      See Also:
      • By.name(java.lang.String)
    • byXpath

      public static org.openqa.selenium.By byXpath(String xpath)
      See Also:
      • By.xpath(java.lang.String)
    • byLinkText

      public static org.openqa.selenium.By byLinkText(String linkText)
      See Also:
      • By.linkText(java.lang.String)
    • byPartialLinkText

      public static org.openqa.selenium.By byPartialLinkText(String partialLinkText)
      See Also:
      • By.partialLinkText(java.lang.String)
    • byId

      public static org.openqa.selenium.By byId(String id)
      See Also:
      • By.id(java.lang.String)
    • byCssSelector

      public static org.openqa.selenium.By byCssSelector(String css)
      See Also:
      • By.cssSelector(java.lang.String)
    • byClassName

      public static org.openqa.selenium.By byClassName(String className)
      See Also:
      • By.className(java.lang.String)
    • byTagName

      public static org.openqa.selenium.By byTagName(String tagName)
      See Also:
      • By.tagName(java.lang.String)