Hoppa till huvudinnehåll

getAttribute

Hämta ett attribut från ett DOM-element baserat på attributnamnet.

Användning
$(selector).getAttribute(attributeName)
Parametrar
NamnTypDetaljer
attributeNamestringefterfrågat attribut
Exempel
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"
})
Returnerar
  • <String|null> return: Värdet på attributet, eller null om det inte är inställt på elementet.

Welcome! How can I help?

WebdriverIO AI Copilot