![]() * Search element with specific class 'Test')] Get parent element 'Test')]/parent::* Multiple conditions 'Test') and contains(text(), 'match this text')] PRO-tip: use the inspector to test your xpath. If your text must match with words beginning with the text or lines starting or ending with that text, use this xpath 2.0 expression: This matches texts like: ‘this match comes up‘ and ‘ matches this’ ![]() If it’s ok to be not so strict, use this more loosely matching: The contains() function tests whether a string attribute contains a specific string (case-insensitive). This matches: elements containing ( just) the text ‘match’ and a button with ( just) the text ‘Save’ĭo you need to strip whitespace from texts in elements before you do the matching, then use this: ![]() It basically comes down to this: Literal match (= must match exactly and completely): I often refer to this post on StackOverflow which has it written down quite neatly: It’s also more descriptive to an untrained eye. When I write selenium/kantu end-to-end test I often need to use xpath to find certain elements.Īnd while it’s definitely not the fastest, searching elements by the text in it, is easy and fast to use.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |