Get Element Tag Name

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Lệnh Get Element Tag Name của API WebDriver trả về tên thẻ của phần tử web được tham chiếu. Ví dụ, nếu phần tử là một <img>, tên thẻ được trả về là "IMG", tương đương với việc gọi Element.tagName trên phần tử đó. Với tài liệu XML/XHTML, cách viết hoa có thể khác.

Cú pháp

Method URI template
GET /session/{session id}/element/{element id}/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ẻ.

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
from selenium import webdriver

session = webdriver.Firefox()
session.get("https://google.com/?hl=en")
search_box = driver.find_element_by_id("q")

print(search_box.tag_name)

Output:

INPUT

Đặc tả

Specification
WebDriver
# get-element-tag-name

Tương thích trình duyệt