I would use next xpath //button[text()='abc']. You have mentioned text() function but I’m not sure syntax was correct. Also you tried to use contains() — it searches partial text and WebDriver gets first element found. I your case it is <button>abcd</button> button