getAttribute

abstract fun getAttribute(xpath: String, attributeName: String): String?

获取由XPath指定的元素的某个HTML属性值 (Attribute)。 这是指在HTML源码中定义的属性。对于动态改变的状态(如输入框的当前值),请使用 getProperty

Return

属性值。如果属性不存在或元素不存在,返回null

Parameters

xpath

目标元素的XPath。

attributeName

要获取的属性名称 (例如 "href", "class", "value"的初始值)。