Find Elements using Regex #159
-
describe what you want to archive Code Sample |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
it's currently not support but should be possible to add as feature. i will have a look how it could be integrated in the DSL to be user friendly. if you have any suggestions or wishes we can discuss them if you want :) |
Beta Was this translation helpful? Give feedback.
-
After thinking of it I feel like I decided to decline the feature request because:
aListOfDocElement.filter { it.toCssSeletor.matches("some regex".toRegex() } What I can imagine is to provide a helper function that is doing the filtering EDIT: |
Beta Was this translation helpful? Give feedback.
-
example: <body>
i'm the body
<header>
<h1>i'm the headline</h1>
<nav>
<ol class='ordered-navigation'>
<li>1st nav item</li>
<li>2nd nav item</li>
<li>3rd nav item</li>
<li>last nav item</li>
</ol>
<ul class='unordered-navigation'>
<li>1st nav item</li>
<li>2nd nav item</li>
<li>3rd nav item</li>
<li>last nav item</li>
</ul>
</nav>
</header>
</body> assuming @Test
fun `can pick element by css selector matching regex`() {
val someRegex = "^(ol|ul).*navigation$".toRegex()
aValidDocument {
findBySelectorMatching(someRegex) {
expectThat(map { it.toCssSelector }).containsExactly(
"html > body > header > nav > ol.ordered-navigation",
"html > body > header > nav > ul.unordered-navigation"
)
}
}
}
@Test
fun `can pick element by css selector matching regex DSL invoke`() {
val someRegex = "^(ol|ul).*navigation$".toRegex()
aValidDocument {
someRegex {
expectThat(map { it.toCssSelector }).containsExactly(
"html > body > header > nav > ol.ordered-navigation",
"html > body > header > nav > ul.unordered-navigation"
)
}
}
} |
Beta Was this translation helpful? Give feedback.
-
The filter idea looks great actually! Thanks a lot for that commit too! So for CSS selectors, I can just use it in the test examples and for other attributes (like id), I can use filters very nice! Like this:
I have one more request too but I am not sure if I should open a new issue for it. Can you add an example of how to import the library when using the SNAPSHOT version of the library |
Beta Was this translation helpful? Give feedback.
-
The snapshot release to jitpack seems to be broken currently. I will have a look within the next days. |
Beta Was this translation helpful? Give feedback.
After thinking of it I feel like I decided to decline the feature request because:
Common to select / Travers an html tree.
aListOfDocElement.filter { it.toCssSeletor.matches("some regex".toRegex() }
What I can imagine is to provide a helper function that is doing the filtering
EDIT:
to catch multiple elements at the same time or b…