Zum Hauptinhalt springen

getAttribute

Erhalte ein Attribut eines DOM-Elements basierend auf dem Attributnamen.

Verwendung
$(selector).getAttribute(attributeName)
Parameter
NameTypeDetails
attributeNamestringangefordertes Attribut
Beispiele
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"
})
Rückgabewert
  • <String|null> return: Der Wert des Attributs oder null, wenn es nicht am Element gesetzt ist.

Welcome! How can I help?

WebdriverIO AI Copilot