On Thursday, May 16, 2013 6:14:34 AM UTC-7, Dan wrote:
> It doesn't look like it's just Chrome actually. I got the same results in
> Firefox. Looks like the stackoverflow answer addresses the issue? If I
> change from button type of button to input type of button it works like you
> would expect.
>
> >> b = Watir::Browser.new :firefox
> => #<Watir::Browser:0x110337500 url="about:blank" title="">
> >> b.goto("file:///Users/admin/Desktop/button.html")
> => "file:///Users/admin/Desktop/button.html"
> >> b.html
> => "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body><button
> value=\"hey\" onclick=\"alert('Hello world!')\" type=\"button\">Click
> Me!</button></body></html>"
> >> b.button.value
> => "hey"
> >> b.button(:value => "hey").exists?
> => false
> >> b.button(:value => "hey").click
> Watir::Exception::UnknownObjectException: unable to locate element, using
> {:value=>"hey", :tag_name=>"button"}
> from
> /Library/Ruby/Gems/1.8/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:490:in
>
> `assert_exists'
> from
> /Library/Ruby/Gems/1.8/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:118:in
>
> `click'
> from (irb):11
> # Changed from button to input type of button
> >> b.refresh
> => []
> >> b.html
> => "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body><input
> type=\"button\" value=\"hey\" onclick=\"alert('Hello world!')\" />Click
> Me!</body></html>"
> >> b.button(:value => "hey").exists?
> => true
>
>
This is likely because for the input tag of type button, there was no
separate text (at least i never see examples of this) the value attribute
determined the text that was displayed for the button.. so for that type of
element value=text The button tag is a lot more robust but seems to be
used less often (perhaps due to (misguided?)advice about
browser compatibility issues?)
But the actual button tag, the value and the text are two different things,
and you may need to specifically use one or the other to select the element
A great example here might be il8n issues, where it's easier for scripting
code to have a consistent value returned by a button, but you may want to
display different text based on a language setting (e.g. a bilingual site)
In that case you may also want your automation to identify by the value,
as it is predictable.
It seems to me on that basis alone, we ought to be able to predictably
select a 'button' tag by its value
> On Wednesday, May 15, 2013 5:35:12 PM UTC-4, Chuck van der Linden wrote:
>>
>> See this SO issue for HTML sample, code samples tried in IRB
>>
>>
>> http://stackoverflow.com/questions/16574999/watir-webdriver-unable-to-identify-button-by-value
>>
>> the short of it. I've got HTML like
>>
>> <button type="button" class="btn fb-user-type" name="fbRadios"
>> value="is_agent" style="">An Agent</button>
>>
>> When I try to identify the button by class, or text, it works, but by
>> value such as
>>
>> b.button(:value => "is_agent").exists?
>>
>> fails (that returns false, most other stuff returns the typical cannot
>> be located message)
>>
>> what the heck? shouldn't this be working? (Chrome on a Mac)
>>
>
--
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]
---
You received this message because you are subscribed to the Google Groups
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.