跳至主要內容

getAttribute

根據屬性名稱從 DOM 元素取得屬性。

用法
$(selector).getAttribute(attributeName)
參數
名稱類型詳細資訊
attributeName字串請求的屬性
範例
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"
})

歡迎!我可以如何幫助您?

WebdriverIO AI Copilot