پرش به محتوای اصلی

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