メインコンテンツにスキップ

getAttribute

属性名に基づいてDOM要素から属性を取得します。

使用方法
$(selector).getAttribute(attributeName)
パラメータ
NameTypeDetails
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