0

I have the following very short code where I expect to be able to click on a button which contains the text Click Me:

from seleniumbase import BaseCase

class MyTestClass(BaseCase):
    def test_basics(self):
        url = "https://seleniumbase.io/demo_page"
        self.open(url)
        self.click_partial_link("Click Me")

But it does not work. I get an error NoSuchElementException. Documentation is HERE.

So how to click on that button using SeleniumBase (https://seleniumbase.io/)?

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Alex
  • 41,580
  • 88
  • 260
  • 469

2 Answers2

2

The selector you're looking for is 'button:contains("Click Me")':

self.click('button:contains("Click Me")')

There are more examples of the SeleniumBase :contains() selector here: https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_contains_selector.py

It's not a standard CSS Selector, as it's specific to SeleniumBase, jQuery, and a few other places, but not everywhere.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
-1

try xpath : //*[text()='your text']

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Jayanth Bala
  • 758
  • 1
  • 5
  • 11
  • Sorry, that does not work for me when I use `//*[text()='Click Me']`. I beleive it is because I am trying to select on a *partial* text. – Alex Aug 31 '21 at 09:50