Get Element Property
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Lệnh Get Element Property của API WebDriver trả về thuộc tính của phần tử web được tham chiếu. Với <input value=foo> khi người dùng đổi giá trị thành bar, thuộc tính được trả về sẽ là bar thay vì giá trị ban đầu foo. Điều này tương đương với việc truy cập thuộc tính trên phần tử.
Cú pháp
| Method | URI template |
|---|---|
GET |
/session/{session id}/element/{element id}/property/{name} |
Tham số URL
session id-
Định danh của phiên.
element id-
Định danh của phần tử web cần lấy tên thẻ.
name-
Định danh của thuộc tính của phần tử web cần lấy.
Lỗi
- Session not created
-
Phiên không tồn tại.
- No such window
-
Đối tượng
windowđã bị loại bỏ, cho biết tab hoặc cửa sổ đã bị đóng. - Unexpected alert open
-
Một lời nhắc của người dùng, chẳng hạn như
window.alert, chặn việc thực thi lệnh cho đến khi nó được xử lý.
Ví dụ
Python:
python
import urllib
from selenium import webdriver
def inline(doc):
return "data:text/html;charset=utf-8,{}".format(urllib.quote(doc))
session = webdriver.Firefox()
session.get(inline("<input value=foo>"))
textbox = driver.find_element_by_tag_name("input")
textbox.send_keys("bar")
print(text_box.get_attribute("value"))
print(text_box.get_property("value"))
Output:
foo bar
Đặc tả
| Thông số kỹ thuật |
|---|
| WebDriver> # get-element-property> |
Tương thích trình duyệt
Xem thêm
- Get Element Attribute command
- What is the difference between properties and attributes? trên Stack Overflow