# getAttribute

Get an attribute from a DOM-element based on the attribute name.

## Usage[​](#usage "Direct link to Usage")

```
await $(selector).getAttribute(attributeName)
```

## Parameters[​](#parameters "Direct link to Parameters")

| Name            | Type     | Details             |
| --------------- | -------- | ------------------- |
| `attributeName` | `string` | requested attribute |

## Examples[​](#examples "Direct link to Examples")

index.html

```
<form action="/submit" method="post" class="loginForm">
    <input type="text" name="name" placeholder="username"></input>
    <input type="text" name="password" placeholder="password"></input>
    <input type="submit" name="submit" value="submit"></input>
</form>
```

getAttribute.js

```
it('should demonstrate the getAttribute command', async () => {
    const form = await $('form')
    const attr = await form.getAttribute('method')
    console.log(attr) // outputs: "post"
})
```

## Returns[​](#returns "Direct link to Returns")

* **\<String|null>** **`return`:** The value of the attribute, or null if it is not set on the element.
