Przejdź do głównej treści

getAttribute

Pobierz atrybut z elementu DOM na podstawie nazwy atrybutu.

Użycie
$(selector).getAttribute(attributeName)
Parametry
NazwaTypSzczegóły
attributeNamestringżądany atrybut
Przykłady
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"
})
Zwraca
  • <String|null> return: Wartość atrybutu lub null, jeśli nie jest ustawiony dla elementu.

Welcome! How can I help?

WebdriverIO AI Copilot