Aller au contenu principal

getAttribute

Obtenir un attribut d'un élément DOM en fonction du nom de l'attribut.

Utilisation
$(selector).getAttribute(attributeName)
Paramètres
NomTypeDétails
attributeNamestringattribut demandé
Exemples
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"
})
Retourne
  • <String|null> return: La valeur de l'attribut, ou null s'il n'est pas défini sur l'élément.

Welcome! How can I help?

WebdriverIO AI Copilot