CSS Flashcards
Выбрать атрибут, который начинается с определенного значения ‘text’
CSS
Символ ^
перед равно [attribute^=value]
a[href^="https"]
- Selects every <a> element whose href attribute value begins with “https”’`</a>
[for^=hobbies-checkbox]
при:
* hobbies-checkbox-1
* hobbies-checkbox-2
* hobbies-checkbox-3
Атрибут href заканчивается значением .pdf
CSS
Символ $
перед равно - [attribute$=value]
a[href$=”.pdf”] Selects every <a> element whose href attribute value ends with “.pdf”</a>
Атрибут содержит внутри часть текста (substring), которую мы указываем
CSS
Символ *
перед равно - [attribute*=value]
a[href*=”w3schools”] Selects every <a> element whose href attribute value contains the substring “w3schools”</a>
Выбрать первый дочерний элемент
CSS
:first-child
p:first-child
- Selects every <p>
element that is the first child of its parent
Выбрать последний дочерний элемент родителя
CSS
:last-child
p:last-child
- Selects every <p>
element that is the last child of its parent
Пример:browser.element('.table').all('td:last-child')
- находит таблицу, в ней последний элемент каждого дочернего <td> (в данном случае - второй столбец)
Выбрать класс
CSS
.class
.intro
- Selects all elements with class=”intro”
Выбрать все элементы с двумя классами
CSS
.class1.class2
.name1.name2
- Selects all elements with both name1 and name2 set within its class attribute
Выбрать все элементы с именем класса class2 у которого есть родитель class1
CSS
.class1 .class2
.name1 .name2
- Selects all elements with name2 that is a descendant of an element with name1
Найти элемент с локатором id
CSS
#id
#firstname
- Selects the element with id=”firstname”
Выбрать все элементы
CSS
*
- Selects all elements
Выбрать элемент (тэг)
CSS
element
p
- Selects all <p> elements
Выбрать все тэги с конкретным классом (все элементы с конкретным классом внутри конкретного тэга)
CSS
element.class
p.intro
- Selects all <p>
elements with class=”intro”
Выбрать все элементы с тэгами <div>
и <p>
CSS
element,element
div, p
Selects all <div>
elements and all <p>
elements
Выбрать все элементы внутри тэга <div>
с тэгом <p>
(с любым уровнем вложенности вглубь)
CSS
element element
div p
- Selects all <p>
elements inside <div>
elements
Выбрать все <p>
элементы где <div>
является родителем
CSS
element>element
div > p
Selects all <p>
elements where the parent is a <div>
element
Выбрать первый элемент <p>
который идёт сразу же после <div>
(на том же уровне)
CSS
element+element
div + p
Selects the first <p>
element that is placed immediately after <div>
elements
Выбрать каждый <ul>
элемент которому предшествует <p>
CSS
element1~element2
p ~ ul
- Selects every <ul>
element that is preceded by a <p>
element
Выбрать все элементы с атрибутом target
CSS
[attribute]
[target]
Selects all elements with a target attribute
Выбрать все атрибуты где target="_blank
CSS
[attribute=value]
[target="_blank"]
- Selects all elements with target="_blank"
Выбрать все элементы с атрибутом title в котором содержится слово flower
CSS
[attribute~=value]
[title~="flower"]
- Selects all elements with a title attribute containing the word “flower”
Выбрать все элементы с атрибутом lang
у которого значение равно en
или начинается с en-
CSS
[attribute|=value]
[lang|="en"]
- Selects all elements with a lang attribute value equal to “en” or starting with “en-“
Найти каждый <p>
элемент который является 2-м дочерним элементом для родительского элемента
- Родитель
- Дочерний 1
- Дочерний 2
CSS
:nth-child()
p:nth-child(2)
- Selects every <p>
element that is the second child of its parent
Является более хрупким, чем :nth-last-of-type()
Выбрать все <p>
элементы, которые являются 2-м дочерним элементом с конца
- Parent
- Child 1
- Child 2
- …
- …
- Child 7
- Child 8
CSS
:nth-last-child()
p:nth-last-child(2)
- Selects every <p>
element that is the second child of its parent, counting from the last child
Выбрать каждый элемент <p>
который является вторым <p>
элементом этого родителя начиная с конца
CSS
:nth-last-of-type()
p:nth-last-of-type(2)
- Selects every <p>
element that is the second <p>
element of its parent, counting from the last child
Выбрать каждый элемент <p>
который является вторым дочерним <p>
элементом у родителя
CSS
:nth-of-type()
p:nth-of-type(2)
Selects every <p>
element that is the second <p>
element of its parent
Выбрать элемент <p>
который является единственным дочерним элементом <p>
этого родителя
CSS
:only-of-type
p:only-of-type
Selects every <p>
element that is the only <p>
element of its parent
Выбрать все <p>
элементы которые являются единственным дочерним у родителя
:only-child
p:only-child
Selects every <p>
element that is the only child of its parent
Комбинация двух значений атрибутов для соблюдения семантичности. Не просто Male, a gender + Male
CSS
[name=gender][value=Male]
Найти среди группы радио кнопок элемент по значению
browser.all('[name=gender]').element_by(have.value(gender)).click()
- Найти все радио баттоны как коллекцию.
- Найти в них значение Male
- Перейти на уровень выше
- Кликнуть
Лучше, чем [name=gender][value=Male]
Переход на уровень выше через XPath
browser.element().element('..').click()