Can I use css locator to return text as a partial match?

Asked 2 years ago, Updated 2 years ago, 98 views

ex)

<a class="sample" id="sample_id" href="../">sample text</a>

You can use either css or xpath to retrieve elements by specifying xpath, as shown below.

exist?(xpath:'//a[@class="sample"]')
exist?(css:'a[class="sample"]')#exist? (css: 'a.sample')

You may want to specify text at times like this, but is it possible to specify text using css selector?

#xpath
exist?(xpath:'//a[text()[contains(., "sample text")]]')
# css
...?

ruby selenium-webdriver

2022-09-30 21:12

1 Answers

I don't think I can.
Similar items include jQuery's:contains selector, but the original CSS does not have these items (as of now).


2022-09-30 21:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.