Chuyển đến nội dung chính

Selectors (CSS

 CSS Selectors

Selector là gì nhỉ, như bạn thấy đây trên web bạn sẽ thấy những label, field ... để hiển thị hoặc nhập thông tin được gọi là các element, thì selector được hiểu như là địa chỉ của các element đó.

How to locate an element on the page, You can identify elements in the content of the web application by Id, Name, Xpath, Link Text, DOM, CSS.
The order to identify an element locator:
 1. find the "id" attribute that are not dynamic
 2. find the unique "name" attribute
 3. find the other possible unique attributes that are not dynamic
 4. If none of the attributes satisfies 1 -> 3, use any other element on the page that has static attributes with the parent/child/sibling relations to locate 
With 3 and 4, in order to unify the way to locate elements in test scripts, we should choose only one type: xpath or css (not use both of them in your scripts, except some special cases)

 id => #id_name
 class => .class_name

1. Using Absolute Path
   You should use > sign to reach an element directly.  (Note: For XPath, we use / sign for this.)
   ex: form>div>input

2. Using Non-Absolute Path
   You should use white space between tags to locate the element. Use "." for class and "#" for id.
   ex: form .form-group #user-message

3. Using Tag Name
   You can write the tag name directly like "form", "div", "img","body", etc. As below figure,
   I wrote the "form" tag to locate the form element.(Note: For XPath we use //tagname for this.)
   ex: form

4. Using Tag & Attribute & Value Trio
   You can use tag[attribute='value'] syntax.
   (Note: For XPath we use tag[@attribute='value'] for this.)
   ex: input[id='user-message']

5. Using Containing Text of an Attribute
   You can use tag[attribute*='containing text'] syntax.
   (Note: For XPath we use tag[contains((@attribute,'containing text')] for this.)
   ex: input[id*='er-messa']

6. Using Starting Text of an Attribute
   You can use tag[attribute^='starting text'] syntax.
   (Note: For XPath we use  tag[starts-with( @attribute, ‘starting text')] for this.)
   ex: input[id^='user']

7. Using Ending Text of an Attribute
   You can use tag[attribute$='ending text'] syntax.
   ex: input[id$='message']

8. Using Comma Operator to Implement OR Operation
   You can use "," operator between two CSS locator statements.
   ex: form#get-input,input#user-message

9. Using Tag and ID
   You can use "Tag#ID"
   ex: input#user-message

10. Using Tag and Class
    You can use "Tag.Class"
    ex: input.form-control

11. Using first-of-type
    You can use "Tag:first-of-type". It will select the first tag element.
    ex: tree-branch>ul>li:first-of-type

12. Using last-of-type
    You can use "Tag:last-of-type". It will select the last tag element.
    ex: .tree-branch>ul>li:last-of-type

    Note: If you want to find the last element or child you can use the below locators.
    ex:
    Tag:nth-last-of-type(n)
    Tag:nth-last-child(n)

13. Using *:last-of-type
    You can use "*last-of-type". It will select the last child of the parent tag.
    ex: .tree-branch>ul>*:last-of-type

14. Using tag:nth-of-type(n)
    You can use "tag:nth-of-type(n)". It will select the nth tag element of the list.
    ex: .tree-branch>ul>li:nth-of-type(3)

15. Using tag:nth-child(n)
    You can use "tag:nth-child(n)". It will select the nth child.
    ex: .tree-branch>ul>li:nth-child(3)

16. Using Sibling "+" Operator
    You can use "E1+ E2". First, it finds E1 and then selects E2.
    ex: li#mercedes + li

17. Exclude a CSS Class Name
    You can exclude any of the class names with :not(.class-name) syntax.
    ex: .btn.btn-info.pull-right:not(.xs-mt-0)

ref: https://www.swtestacademy.com/css-selenium/

Nhận xét

Bài đăng phổ biến từ blog này

3Q6S - Tiêu chuẩn chất lượng công ty nhật

+  Ý nghĩa của 3Q6S -          Quality company: công ty tốt -          Quality worker: nhân viên tốt -          Quality Products : sản phẩm tốt -          Seiri : sắp xếp gọn gàng -          Seiton: đặt ngăn nắp, đúng chỗ -          Seiketsu : tinh khiết, sáng sủa -          Seisou: quét dọn sạch sẽ -          Saho : tác phong, hành động đúng -          Shitsuke : kỷ luật, nề nếp     – Lấy các chữ đầu của các mục trên để gọi là 3Q6S.        * Sắp xếp gọn gàng bao gồm ý nghĩa “Phân chia những vật cần thiết và không cần thiết, những vật không cần thiết không đặt ở nơi làm việc...

Tổng quan về solfware testing

Chương 1: Tổng quan về test phần mềm         1.1 Các giai đoạn test         1.2 Định nghĩa về test         1.3 Mục tiêu của test         1.4 Vai trò và nhiệm vụ của Tester. Chương 2: Những yêu cầu cần thiết khi thực hiện test        2.1 Ý nghĩa những tài liệu tester cần hiểu trước khi bắt đầu test        2.2 Hướng test cụ thể trong phần mềm Chương 3: Quy trình test       Sơ đồ tổng quát. Chương 4: Phương pháp test và kỹ thuật thiết kế testcase       4.1 Phương pháp test       4.2 Loại test       4.3 Test case Chương 5: Lỗi phổ biến trong phần mềm và cách Report Bug       5.1 13 lỗi phổ biến trong phần mềm (Bug type).       5.2 Report Bug Template. Chương 6: Test Plan và thế nào là Tester tốt A. TEST PLAN       I. Definitions:   ...

Các hàm xử lý về thời gian trong mySQL - Date and Time Functions

Tên hàm Mô tả ADDDATE()  = Add time values (intervals) to a date value ADDTIME()  = Add time CONVERT_TZ()  = Convert from one timezone to another CURDATE()  = Return the current date CURRENT_DATE(), CURRENT_DATE = Synonyms for CURDATE() CURRENT_TIME(), CURRENT_TIME  = Synonyms for CURTIME() CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP  = Synonyms for NOW() CURTIME() = Return the current time DATE_ADD() = Add time values (intervals) to a date value DATE_FORMAT() = Format date as specified DATE_SUB() = Subtract a time value (interval) from a date DATE() = Extract the date part of a date or datetime expression DATEDIFF() = Subtract two dates DAY() = Synonym for DAYOFMONTH() DAYNAME() = Return the name of the weekday DAYOFMONTH() = Return the day of the month (0-31) DAYOFWEEK() = Return the weekday index of the argument DAYOFYEAR() = Return the day of the year (1-366) EXTRACT() = Extract part of a date FROM_DAYS() = Convert a day number to...