Very similar to Not able to click Button(element) on Selenium webdriver
The button is defined in the web page as:
<button class="gigantic-long-string-gwtui-etc"
type="button" style="width: 60px" tabIndex="200">OK</button>
I'm using Geb. I defined the button as follows:
systemUseNotification (wait:true) { $("button", text:"OK") }
and tried to click the button with:
waitFor(60) {systemUseNotification.click()}
The code was able to find the button, but click() never worked. I had to use a strange work-around sending the ENTER key to the button
systemUseNotification << Keys.chord(Keys.ENTER))
The other control that the code could find but not click was defined by
templateTab(wait:true) { $("td" , text:"Templates")}
This is a table cell that changes the view when you click on it.
Again, calling click() on this templateTab did not do anything. This is even with waitFor
wrapped around it, and verifying the code found the control.
The actual definition in the HTML is <td class="main-menu-item-text">Templates<td>
What did work was $(class:'main-menu-item-text', text:"Templates").click()
But I really do not like having to specify the class name as it defeats the purpose of having change-resistant test code.
Same question where I am trying to click a div control button defined as
I want to call use something like:
$("div", title:"Switch Dashboards").click()
But this does not work either.
Please tell me what I am doing wrong.
I found the following technique worked:
waitFor {$("td", class:contains("text"), text:"Templates").click()}
I still prefer to avoid having to know anything about the class, though, but at least this reduced the size of the string I have to match.
I tried, for example class:contains(~/.*/)
and class:~/.*/
so I could be "class-agnostic", but those always resulted in stale.