# 4.4. FindElement

`driver.findElement(By.class)`, hàm `findElement` trả về đối tượng đầu tiên mà nó tìm thấy dựa trên `By.class truyền vào. Nếu ko tìm được đối lượng nó sé trả về Error`

| **Strategy**             | **Syntax**                                                  | **Descriptions**                                      |
| ------------------------ | ----------------------------------------------------------- | ----------------------------------------------------- |
| **By ID**                | **driver.findElement(By.id(\<element ID>))**                | **Locates an element the using ID attribute**         |
| **By Name**              | **driver.findElement(By.name(\<element name>))**            | **Locates an element the using name attribute**       |
| **By class name**        | **driver.findElement(By.className(\<element class>))**      | **Locates an element the using class name attribute** |
| **By tag name**          | **driver.findElement(By.tagName(\<htmltagname>))**          | **Locates an element using the HTML tag**             |
| **By link text**         | **driver.findElement(By.linkText(\<linktext>))**            | **Locates link using its text**                       |
| **By partial link text** | **driver.findElement(By.partialLinkText(\<linktext>))**     | **Locates link using it's partial text**              |
| **By css**               | **driver.findElement(By.cssSelector(\<css selector>))**     | **Locates element using the CSS selector**            |
| **By Xpath**             | **driver.findElement(By.xpath(\<xpath query expression>))** | **Locates element using the Xpath selector**          |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tvn.gitbook.io/selenium-java/findelement.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
