Pular para o conteúdo principal

getAttribute

Obter um atributo de um elemento DOM com base no nome do atributo.

Uso
$(selector).getAttribute(attributeName)
Parâmetros
NomeTipoDetalhes
attributeNamestringatributo solicitado
Exemplos
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"
})
Retorna
  • <String|null> return: O valor do atributo, ou null se não estiver definido no elemento.

Welcome! How can I help?

WebdriverIO AI Copilot