Hướng dẫn inner html and inner text - html bên trong và văn bản bên trong

Xem xét mã HTML sau đây.

<div id="mylinks">
  This is my <b>link collection</b>:
  <ul>
    <li><a href="www.borland.com">Bye bye <b>Borland</b> </a></li>
    <li><a href="www.microfocus.com">Welcome to <b>Micro Focus</b></a></li>
  </ul>
</div>

Bảng sau đây chi tiết các thuộc tính khác nhau trả về.

Mã số Giá trị trả lại
Browser.DOMEMENT ("// Div [@id = 'mylinks']"). getProperty ("TextContents")
This is my link collection:
Browser.DOMEMENT ("// Div [@id = 'mylinks']").
This is my link collection:Bye bye Borland Welcome to Micro Focus
Browser.DOMEMENT ("// Div [@id = 'mylinks']").
This is my <b>link collection</b>:
<ul> 
  <li><a href="www.borland.com">Bye bye <b>Borland</b></a></li>
  <li><a href="www.microfocus.com">Welcome to <b>Micro Focus</b></a></li> 
</ul>

Lưu ý: Trong thử nghiệm lụa 13,5 trở lên, khoảng trắng trong các văn bản, được lấy thông qua thuộc tính TextContents của một phần tử, được cắt tỉa liên tục trên tất cả các trình duyệt được hỗ trợ. Đối với một số phiên bản trình duyệt, xử lý khoảng trắng này khác với các phiên bản thử nghiệm lụa trước khi thử nghiệm lụa 13,5. Bạn có thể kích hoạt lại hành vi cũ bằng cách đặt tùy chọn OPT_CompiTion thành phiên bản thấp hơn 13.5.0. Ví dụ: để đặt tùy chọn thành Test Silk Test 13.0, hãy nhập phần sau vào tập lệnh của bạn: In Silk Test 13.5 or later, whitespace in texts, which are retrieved through the textContents property of an element, is trimmed consistently across all supported browsers. For some browser versions, this whitespace handling differs to Silk Test versions prior to Silk Test 13.5. You can re-enable the old behavior by setting the OPT_COMPATIBILITY option to a version lower than 13.5.0. For example, to set the option to Silk Test 13.0, type the following into your script:

'VB .NET code
Agent.SetOption("OPT_COMPATIBILITY", "13.0.0")

Thí dụ

Nhận văn bản bên trong của một phần tử:

Đặt văn bản = phần tử.innertext;

Hãy tự mình thử »

Thêm ví dụ dưới đây.


Định nghĩa và cách sử dụng

Thuộc tính

This is my link collection:
4 đặt hoặc trả về nội dung văn bản của một phần tử.

Sự khác biệt giữa InternHTML, InnerText và TextContent innerHTML, innerText and textContent

Xem bên dưới


Cú pháp

Trả về nội dung văn bản của một phần tử hoặc nút:

hoặc

Đặt nội dung văn bản của một phần tử hoặc nút:

hoặc

Đặt nội dung văn bản của một phần tử hoặc nút:

Giá trị tài sảnTài sản
Sự mô tảchữ

Nội dung văn bản của phần tử.

Giá trị trả vềTài sản
Sự mô tảchữ


Sự khác biệt giữa InternHTML, InnerText và TextContent innerHTML, innerText and textContent

Xem bên dưới
The text content of the element, including all spacing and inner HTML tags.
Cú pháp
Just the text content of the element and all its children, without CSS hidden text spacing and tags, except