… <form class=“form_upload> <div> <div class=“row_element_3 row tile_fixed”> <div class=“button_cell wrapper_tile”> <button type=“submit” class=“button_submit wrapper_button”> </button> </div> </div> </div> </form> …
.button_submit
<form class=“afhfsdh__”> <div> <div class=“hfgeyq fjjs qurlzn”> <div class=“fjdfmzn fjafjd”> <button type=“submit” class=“ajffalf wjf_fjaap”></button> </div> </div> </div> </form> …
css: form button[type='submit']
, instead of XPath: //form//button[@type='submit']
<form class=“form_upload> <div> <div class=“row_element_3 row tile_fixed”> <div class=“button_cell wrapper_tile”> <button type=“submit” class=“button_submit wrapper_button”></button> </div> </div> </div> </form>
button: .button_submit
, while the .wrapper_button
class is optional, but if it is needed to point to our class, we can add it immediately after the first css class is specified: css: .button_submit.wrapper_button
. The order of classes does not matter, so you can swap them: .wrapper_button.button_submit .
css: button.
button.button_submit
data-id
attribute to our button button. Then the attributes using the css selector can be accessed through curly brackets: [data-id='submit']
. Additionally, you can omit the attribute value after the character equal to [data-id]
. Such a selector will find you all the elements that have a data-id
attribute with any value inside. You can also specify the class attribute to search for our button: [class='button_submit']
, but in CSS, as you already know, you can be lazy and write like this: .button_submit
. Putting it all together is also quite simple: button[type='submit'].button_submit
<form class=“form_upload> <div> <div class=“row_element_3 row tile_fixed”> <div class=“button_cell wrapper_tile”> <button type=“submit” class=“button_submit wrapper_button”></button> </div> </div> </div> </form>
css:form > div > div > div > button.button_submit
>
sign allows you to find an element exclusively in the ancestor inside. But to write all the elements is unnecessary, since in CSS there is the ability to search in all descendants, this character is a space “ “
. Using this pointer we can quickly find the element inside the form:css: form > div > div > div > button.button_submit
css: form button,button_submit
span
: <form class=“form_upload> <div> <div class=“row_element_3 row tile_fixed”> <div class=“button_cell wrapper_tile”> <div class=“content”></div> <span data-id=“link”></span> <!-- data-id --> <button type=“submit” class=“button_submit wrapper_button”> <!-- --></button> </div> </div> </div> </form>
[data-id='link'] + button
will find the button
, which has a relative higher by one attribute with the data-id=”link”
attribute. This pointer can be used when the previous element has an id or a unique attribute, and the element that is next to the one you need does not have such identifiers. So, using the + css symbol, the selector will find the next relative. div + span[data-id='link'] + button
button[class*='submit']
- from the long class name button_submit
we take only the right side of submit
and add to the sign = the symbol *. You can also find the word cell
from the class value: div[class*='cell']
.^=
and $=
, but this task is not as common as searching for the attribute value.a[href^=“https:”]
- will find all links that start with https,a[href$=“.pdf”]
- will find all links that end in .pdf. <div class=“tiles”> <div class=“tile”>…</div> <div class=“tile”>…</div> </div>
div class=“tile”
in div class=“tiles”
? Option two: div > div:nth-of-type(2) div > div:nth-child(2)
<div class=“tiles”> <a class=“link”>…</a> <!—1—> <div class=“tile”>…</div><!—2—> <div class=“tile”>…</div><!—3—> </div>
div > div:nth-of-type(2)
div > div:nth-child(2)
nth-child
searches for the second div
, which is a descendant of the parent. Second<div>at the element
<div class = “tiles”>This is the third line. In turn, the
nth-of-type
searches for the second element in the parent.<div class = “tiles”>which must be a tag
divThis is line number two.
nth-of-type
wherever possible. If you figured out the example above, I recommend that you always pay attention to the number of identical elements in an ancestor, using nth-child
, and then you will not care where they put the link<a>: upstairs between
<div>or at the bottom of the block, always the selector
div:nth-child(2)
will still point to the desired element - the second div element inside the block.[attribute=“value”]
and for our case we can find the element like this [id=“value”]
. And what if there is a faster way to search by id element? #value. “#” - , id.
<button>
… <div> <div class=“tile_wrapper tile content”> <div class=“row row_content”> <div class=“outline description__on”></div> <div class=“outline description__off button_send hover_mouse”> <button class=“outline button_send”></button> </div> </div> </div> </div>
Source: https://habr.com/ru/post/350368/
All Articles