> For the complete documentation index, see [llms.txt](https://softlr.gitbook.io/selenium-webdriver-extensions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://softlr.gitbook.io/selenium-webdriver-extensions/api/by.md).

# By

The `By` class is usually used as a factory for all sorts of selenium Selectors. Each type of the selector supported by Selenium can be created by a specific static method in this class. SWE is also following this concept by providing a custom version of the `By` class that can create all Selenium selector types but it also can create new types of selectors that are provided in this library.

## By alias

The easiest way of creating selectors in Selenium WebDriver is by using `By` static class members. Since in C# static class cannot be inherited, another version of this class has been created that exposes new types of selectors apart from the ones provided by Selenium WebDriver.

{% tabs %}
{% tab title="C#" %}
The most convenient way of using this class is by specifying the alias.

```csharp
using By = Selenium.WebDriver.Extensions.By;
```

{% endtab %}

{% tab title="C#" %}
The instances of the selector types added by this library can also be created by simply invoking their constructors.

```csharp
var jQuerySelector = new JQuerySelector("div.myClass:visible");
var sizzleSelector = new SizzleSelector("div.myClass:visible");
```

{% endtab %}
{% endtabs %}

## By.JQuerySelector

{% tabs %}
{% tab title="C#" %}
Gets a mechanism to find elements matching jQuery selector.

```csharp
var element = driver.FindElement(By.JQuerySelector(":text"));
```

{% endtab %}

{% tab title="C#" %}
Gets a mechanism to find elements matching jQuery selector with the nested context. This will invoke the nested context selector first, and on the results of this selector will perform the new query further narrowing the results.

```csharp
var element = driver.FindElement(By.JQuerySelector(":text", By.JQuerySelector("div.myClass")));
```

{% endtab %}

{% tab title="C#" %}
Gets a mechanism to find elements matching jQuery selector and overriding the jQuery variable name. This can be useful in cases where the variable name conflicts with other libraries.

```csharp
var element = driver.FindElement(By.JQuerySelector(":text", variable: "myJQuery"));
```

{% endtab %}
{% endtabs %}

## By.SizzleSelector

{% tabs %}
{% tab title="C#" %}
Gets a mechanism to find elements matching Sizzle selector.

```csharp
var element = driver.FindElement(By.SizzleSelector(":text"));
```

{% endtab %}

{% tab title="C#" %}
Gets a mechanism to find elements matching Sizzle selector with the nested context. This will invoke the nested context selector first, and on the results of this selector will perform the new query further narrowing the results.

```csharp
var element = driver.FindElement(By.SizzleSelector(":text", By.SizzleSelector("div.myClass")));
```

{% endtab %}
{% endtabs %}

## By.ClassName

Gets a mechanism to find elements by their CSS class.

```csharp
var element = driver.FindElement(By.ClassName("myClass"));
```

## By.CssSelector

Gets a mechanism to find elements by their cascading style sheet (CSS) selector.

```csharp
var element = driver.FindElement(By.CssSelector("div.myClass"));
```

## By.Id

Gets a mechanism to find elements by their ID.

```csharp
var element = driver.FindElement(By.Id("myId"));
```

## By.Name

Gets a mechanism to find elements by their name.

```csharp
var element = driver.FindElement(By.Name("myName"));
```

## By.TagName

Gets a mechanism to find elements by their tag name.

```csharp
var element = driver.FindElement(By.TagName("div"));
```

## By.LinkText

Gets a mechanism to find elements by their link text.

```csharp
var element = driver.FindElement(By.LinkText("text"));
```

## By.PartialLinkText

Gets a mechanism to find elements by a partial match on their link text.

```csharp
var element = driver.FindElement(By.PartialLinkText("text"));
```

## By.XPath

Gets a mechanism to find elements by an XPath query. When searching within a `IWebElement` using xpath be aware that `IWebDriver` follows standard conventions: a search prefixed with `/` will search the entire document, not just the children of this current node. Use `./` to limit your search to the children of this `IWebElement`.

```csharp
var element = driver.FindElement(By.XPath("//body/div"));
```
