Перейти к основному содержимому

getAttribute

Получение атрибута DOM-элемента на основе имени атрибута.

Использование
$(selector).getAttribute(attributeName)
Параметры
ИмяТипПодробности
attributeNamestringзапрашиваемый атрибут
Примеры
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"
})
Возвращает
  • <String|null> return: Значение атрибута или null, если атрибут не установлен на элементе.

Welcome! How can I help?

WebdriverIO AI Copilot