Selenium WebElement中'property'和'attribute'之间有什么区别?

Jcy*_*rss 6 selenium

Selenium WebElement有两种方法,在Python中,它们是'get_attribute'和'get_property'.文档非常简单,对我来说不清楚.

他们在地球上有什么不同?

nee*_*_jn 7

一个属性是一个给定的DOM节点的静态属性,作为其中属性是DOM节点对象的计算性能.属性的示例将是checked复选框value或输入字段的状态.作为属性将是href锚标记或type输入DOM的位置.

<a href="https://google.com" id="hello">Hello World</a>
<input type="checkbox" id="foo" checked>
<input type="text" id="bar" value="cheesecake">
Run Code Online (Sandbox Code Playgroud)
link_location = document.querySelector('#hello').getAttribute('href')
// # href="https://google.com"

input_checkbox = document.querySelector('#foo').getAttribute('type')
// # type="checkbox"

checkbox_checked = document.querySelector('#foo').checked
// # computed property of the DOM node

textbox_value = document.querySelector('#bar').value
// # computed property of the DOM node
Run Code Online (Sandbox Code Playgroud)

https://www.w3schools.com/jsref/dom_obj_all.asp