Reputation: 571
I am playing around with rpsec and watir-webdriver, and am encountering a strange issue where I can click into a button, but I cannot interact with (or change) the text in the span inside.
This is what the html looks like:
<button class="pure-button toggle-mode button-link edit-text-button-element" data-reactid=".0.1.0.1.1.0.0.0.0" title="Edit">
<span class="value false" data-reactid=".0.1.0.1.1.0.0.0.0.0">Untitled</span>
</span>
</button>
Right now my ruby code looks like this:
foo = @browser.button(:class, 'pure-button toggle-mode button-link edit-text-button-element')
foo.click
foo.span.set('Hello')
Running this gives me the initial error expected Hash or (:how, 'what'), got ["Hello"]
Any thoughts on what I'm doing wrong here?
Upvotes: 3
Views: 820
Reputation: 571
Found a solution that works: after clicking to interact with the element, I was able to set text by using send_keys
. So I did this:
foo = @browser.button(:class, 'pure-button toggle-mode button-link edit-text-button-element')
foo.click
@browser.send_keys {keystrokes simulated here}
Upvotes: 2
Reputation: 669
That is because you cannot set text of the span in watir-webdriver. At least so easily. But if you will do for example:
puts foo.span.text
it will work. Here is the full list of what you can do with span: Usefull Link
Of course there is the way to change the text in your span:
browser.execute_script("arguments[0].textContent= 'Hello'", foo.span)
But I cannot imagine the situation when it will be really necessary for the real testing in a real world.
Upvotes: 1
Reputation: 4194
The class
locator only accepts a single class.
If you need all of the classes for it to be unique do:
@browser.button(css: ".pure-button.toggle-mode.button-link.edit-text-button-element")
Upvotes: 0