-2

I'm having an issue with css ( cannot find the proper way how to write it)

<div class="d-flex flex-row align-items-center justify-content-end col-6">
<button disabled="" class="btn btn-primary disabled">'Text 1'</button>
<button disabled="" class="btn btn-primary disabled">'Text 2'</button>
<button disabled="" class="btn btn-primary disabled">'Text 3'</button>
<button disabled="" class="btn btn-primary disabled">'Text 4'</button>
<button disabled="" class="btn btn-primary disabled">'Text 5'</button>
<button disabled="" class="btn btn-primary disabled">'Text 6'</button>
</div>

How can I write it down if I want to select 'Text #3' for example? And one more, how can I write down smth like parrent[class='smth'] child['Text 3']

3 Answers3

0

If I understand this correctly you can do something like this:

<div class="d-flex flex-row align-items-center justify-content-end col-6">
  <button disabled="" class="btn btn-primary disabled">'Text 1'</button>
  <button disabled="" class="btn btn-primary disabled">'Text 2'</button>
  <button disabled="" class="btn btn-primary disabled">'Text 3'</button>
  <button disabled="" class="btn btn-primary disabled">'Text 4'</button>
  <button disabled="" class="btn btn-primary disabled">'Text 5'</button>
  <button disabled="" class="btn btn-primary disabled">'Text 6'</button>
</div>

CSS:

div button:nth-child(2) { background: red; }

Example codepen: https://codepen.io/brooksrelyt/pen/ZVMPwR

brooksrelyt
  • 3,925
  • 5
  • 31
  • 54
  • nope, cause number of child changes(it's dynamic). It has Text 1, Text 2 and so on. so I need to find through button,that has text 'Text #'. – Dmytro Ivanenko Jan 10 '19 at 15:36
0

CSS selector (at least one that is supported by Selenium) doesn't allow to locate elements by text (:contains() pseudo-class is not supported). You can try to use XPath like below instead:

//div[contains(@class, 'flex-row')]/button[text()='Text 3']
Andersson
  • 51,635
  • 17
  • 77
  • 129
0

You can't

CSS is a markup language. Per the specifications, the selectors work on structure, not on content.

There was talk of adding a :contains() pseudo-class but I guess it was scrapped.

Community
  • 1
  • 1
MivaScott
  • 1,763
  • 1
  • 12
  • 30